summaryrefslogtreecommitdiffstats
path: root/hl/tools/gif2h5
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-10-01 16:47:45 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-10-01 16:47:45 (GMT)
commit1ba1f2f3222cbe8df0bf601929a4bffd478d7e02 (patch)
treeae51dfc33cf40432dad25a5088767115a98f195e /hl/tools/gif2h5
parent8eef7d295cc3dd134aef0a826f1de4287629996d (diff)
downloadhdf5-1ba1f2f3222cbe8df0bf601929a4bffd478d7e02.zip
hdf5-1ba1f2f3222cbe8df0bf601929a4bffd478d7e02.tar.gz
hdf5-1ba1f2f3222cbe8df0bf601929a4bffd478d7e02.tar.bz2
Source formatted
Diffstat (limited to 'hl/tools/gif2h5')
-rw-r--r--hl/tools/gif2h5/decompress.c176
-rw-r--r--hl/tools/gif2h5/gif.h81
-rw-r--r--hl/tools/gif2h5/gif2hdf.c46
-rw-r--r--hl/tools/gif2h5/gif2mem.c181
-rw-r--r--hl/tools/gif2h5/gifread.c311
-rw-r--r--hl/tools/gif2h5/h52gifgentst.c66
-rw-r--r--hl/tools/gif2h5/hdf2gif.c233
-rw-r--r--hl/tools/gif2h5/hdfgifwr.c211
-rw-r--r--hl/tools/gif2h5/writehdf.c57
9 files changed, 637 insertions, 725 deletions
diff --git a/hl/tools/gif2h5/decompress.c b/hl/tools/gif2h5/decompress.c
index 8cd8a8e..9df843a 100644
--- a/hl/tools/gif2h5/decompress.c
+++ b/hl/tools/gif2h5/decompress.c
@@ -15,45 +15,43 @@
#include "gif.h"
-GIFWORD iWIDE, iHIGH, eWIDE, eHIGH, expand, numcols, strip, nostrip;
-unsigned long cols[256];
-char *cmd;
+GIFWORD iWIDE, iHIGH, eWIDE, eHIGH, expand, numcols, strip, nostrip;
+unsigned long cols[256];
+char * cmd;
FILE *fp;
-static GIFWORD
- XC = 0, YC = 0, /* Output X and Y coords of current pixel */
- InitCodeSize, /* Starting code size, used during Clear */
- CodeSize, /* Code size, read from GIF header */
- BytesPerScanline, /* Bytes per scanline in output raster */
- IWidth, IHeight; /* image dimensions */
-static int
- BitOffset = 0, /* Bit Offset of next code */
- Pass = 0, /* Used by output routine if GIFWORDerlaced pic */
- OutCount = 0, /* Decompressor output 'stack count' */
- Code, /* Value returned by ReadCode */
- MaxCode, /* limiting value for current code size */
- ClearCode, /* GIF clear code */
- EOFCode, /* GIF end-of-information code */
- CurCode, OldCode, InCode, /* Decompressor variables */
- FirstFree, /* First free code, generated per GIF spec */
- FreeCode, /* Decompressor, next free slot in hash table */
- FinChar, /* Decompressor variable */
- DataMask, /* AND mask for data size */
- ReadMask; /* Code AND mask for current code size */
+static GIFWORD XC = 0, YC = 0, /* Output X and Y coords of current pixel */
+ InitCodeSize, /* Starting code size, used during Clear */
+ CodeSize, /* Code size, read from GIF header */
+ BytesPerScanline, /* Bytes per scanline in output raster */
+ IWidth, IHeight; /* image dimensions */
+static int BitOffset = 0, /* Bit Offset of next code */
+ Pass = 0, /* Used by output routine if GIFWORDerlaced pic */
+ OutCount = 0, /* Decompressor output 'stack count' */
+ Code, /* Value returned by ReadCode */
+ MaxCode, /* limiting value for current code size */
+ ClearCode, /* GIF clear code */
+ EOFCode, /* GIF end-of-information code */
+ CurCode, OldCode, InCode, /* Decompressor variables */
+ FirstFree, /* First free code, generated per GIF spec */
+ FreeCode, /* Decompressor, next free slot in hash table */
+ FinChar, /* Decompressor variable */
+ DataMask, /* AND mask for data size */
+ ReadMask; /* Code AND mask for current code size */
/*MODIFICATIONS*/
-GIFBYTE tempbyte[10];
-GIFBYTE * tempGIFBYTEptr[10];
-GIFWORD tempint[10];
-GIFWORD ImageCount = 0;
+GIFBYTE tempbyte[10];
+GIFBYTE *tempGIFBYTEptr[10];
+GIFWORD tempint[10];
+GIFWORD ImageCount = 0;
/*END MODIFICATION*/
boolean Interlace, HasColormap;
-GIFBYTE *Image; /* The result array */
-GIFBYTE *RawGIF; /* The heap array to hold it, raw */
-GIFBYTE *Raster; /* The raster data stream, unblocked */
+GIFBYTE *Image; /* The result array */
+GIFBYTE *RawGIF; /* The heap array to hold it, raw */
+GIFBYTE *Raster; /* The raster data stream, unblocked */
/* The hash table used by the decompressor */
@@ -66,7 +64,7 @@ int OutCode[1025];
/* The color map, read from the GIF header */
-int numused;
+int numused;
/*
* Fetch the next code from the raster data stream. The codes can be any
@@ -82,7 +80,7 @@ ReadCode(void)
int RawCode, ByteOffset;
ByteOffset = BitOffset / 8;
- RawCode = Raster[ByteOffset] + (0x100 * Raster[ByteOffset + 1]);
+ RawCode = Raster[ByteOffset] + (0x100 * Raster[ByteOffset + 1]);
if (CodeSize >= 8)
RawCode += (0x10000 * Raster[ByteOffset + 2]);
@@ -95,10 +93,8 @@ ReadCode(void)
static void
AddToPixel(GIFBYTE Index)
{
- if (YC<IHeight)
- *(Image + YC * BytesPerScanline + XC) = Index;
-
-
+ if (YC < IHeight)
+ *(Image + YC * BytesPerScanline + XC) = Index;
/* Update the X-coordinate, and if it overflows, update the
* Y-coordinate */
@@ -113,40 +109,41 @@ AddToPixel(GIFBYTE Index)
if (!Interlace) {
YC++;
- } else {
+ }
+ else {
switch (Pass) {
- case 0:
- YC += 8;
-
- if (YC >= IHeight) {
- Pass++;
- YC = 4;
- }
-
- break;
- case 1:
- YC += 8;
-
- if (YC >= IHeight) {
- Pass++;
- YC = 2;
- }
-
- break;
- case 2:
- YC += 4;
-
- if (YC >= IHeight) {
- Pass++;
- YC = 1;
- }
-
- break;
- case 3:
- YC += 2;
- break;
- default:
- break;
+ case 0:
+ YC += 8;
+
+ if (YC >= IHeight) {
+ Pass++;
+ YC = 4;
+ }
+
+ break;
+ case 1:
+ YC += 8;
+
+ if (YC >= IHeight) {
+ Pass++;
+ YC = 2;
+ }
+
+ break;
+ case 2:
+ YC += 4;
+
+ if (YC >= IHeight) {
+ Pass++;
+ YC = 1;
+ }
+
+ break;
+ case 3:
+ YC += 2;
+ break;
+ default:
+ break;
}
}
}
@@ -159,20 +156,20 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead)
{
int i;
- XC = 0;
- YC = 0;
- Pass = 0;
- OutCount = 0;
+ XC = 0;
+ YC = 0;
+ Pass = 0;
+ OutCount = 0;
BitOffset = 0;
- DataMask = (1 << ((GifHead->PackedField & 0x07) +1)) -1;
- Raster = GifImageDesc->GIFImage;
+ DataMask = (1 << ((GifHead->PackedField & 0x07) + 1)) - 1;
+ Raster = GifImageDesc->GIFImage;
/* Check for image seperator */
/* Now read in values from the image descriptor */
- IWidth = GifImageDesc->ImageWidth;
- IHeight = GifImageDesc->ImageHeight;
+ IWidth = GifImageDesc->ImageWidth;
+ IHeight = GifImageDesc->ImageHeight;
Interlace = (uint8_t)(GifImageDesc->PackedField & 0x40);
/*
@@ -187,9 +184,9 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead)
* compute decompressor constant values, based on this code size.
*/
- CodeSize = GifImageDesc->CodeSize;
+ CodeSize = GifImageDesc->CodeSize;
ClearCode = (1 << CodeSize);
- EOFCode = ClearCode + 1;
+ EOFCode = ClearCode + 1;
FreeCode = FirstFree = ClearCode + 2;
/*
@@ -201,8 +198,8 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead)
CodeSize++;
InitCodeSize = CodeSize;
- MaxCode = (1 << CodeSize);
- ReadMask = MaxCode - 1;
+ MaxCode = (1 << CodeSize);
+ ReadMask = MaxCode - 1;
/*
* Read the raster data. Here we just transpose it from the GIF array to
@@ -212,7 +209,7 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead)
/* Allocate the Image */
- if (!(Image = (GIFBYTE *)malloc((size_t)IWidth*(size_t)IHeight))) {
+ if (!(Image = (GIFBYTE *)malloc((size_t)IWidth * (size_t)IHeight))) {
printf("Out of memory");
exit(EXIT_FAILURE);
}
@@ -233,13 +230,14 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead)
*/
if (Code == ClearCode) {
CodeSize = InitCodeSize;
- MaxCode = (1 << CodeSize);
+ MaxCode = (1 << CodeSize);
ReadMask = MaxCode - 1;
FreeCode = FirstFree;
CurCode = OldCode = Code = ReadCode();
- FinChar = CurCode & DataMask;
+ FinChar = CurCode & DataMask;
AddToPixel((GIFBYTE)FinChar);
- } else {
+ }
+ else {
/*
* If not a clear code, then must be data: save same as CurCode
* and InCode
@@ -251,7 +249,7 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead)
* repeat the last character decoded
*/
if (CurCode >= FreeCode) {
- CurCode = OldCode;
+ CurCode = OldCode;
OutCode[OutCount++] = FinChar;
}
@@ -266,11 +264,11 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead)
}
OutCode[OutCount++] = Suffix[CurCode];
- CurCode = Prefix[CurCode];
+ CurCode = Prefix[CurCode];
}
/* The last code in the chain is treated as raw data. */
- FinChar = CurCode & DataMask;
+ FinChar = CurCode & DataMask;
OutCode[OutCount++] = FinChar;
/*
@@ -288,7 +286,7 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead)
*/
Prefix[FreeCode] = OldCode;
Suffix[FreeCode] = FinChar;
- OldCode = InCode;
+ OldCode = InCode;
/*
* Point to the next slot in the table. If we exceed the current
diff --git a/hl/tools/gif2h5/gif.h b/hl/tools/gif2h5/gif.h
index 0c0f963..cb54b9b 100644
--- a/hl/tools/gif2h5/gif.h
+++ b/hl/tools/gif2h5/gif.h
@@ -16,7 +16,7 @@
* Purpose: GIF Header file
*/
#ifndef GIF_H_
-#define GIF_H_ 1
+#define GIF_H_ 1
#include <stdio.h>
#include <stdlib.h>
@@ -39,10 +39,10 @@ typedef unsigned char boolean;
#endif
#ifndef false
-#define false 0
+#define false 0
#endif
#ifndef true
-#define true 1
+#define true 1
#endif
/* Set the EndianOrder.
@@ -50,7 +50,7 @@ typedef unsigned char boolean;
** Set EndianOrder = 0 if machine is little endian
** EndianOrder = 1 if machine is big endian.
*/
-extern int EndianOrder;
+extern int EndianOrder;
/*
** The GIF header format.
@@ -59,31 +59,30 @@ extern int EndianOrder;
** descriptor, and the global color table for the GIF image.
*/
typedef struct _GifHeader { /* Offset Description */
- GIFBYTE PackedField; /* 0Ah Color Information */
+ GIFBYTE PackedField; /* 0Ah Color Information */
GIFWORD TableSize;
- GIFBYTE ImageCount; /* Keep a count of the number of images */
+ GIFBYTE ImageCount; /* Keep a count of the number of images */
GIFBYTE CommentCount;
GIFBYTE ApplicationCount;
GIFBYTE PlainTextCount;
GIFBYTE HDFPalette[256][3];
- GIFBYTE HeaderDump[6]; /* GIFBYTE array to dump header contents */
- GIFBYTE LSDDump[7]; /* Logical Screen Descriptor dump */
+ GIFBYTE HeaderDump[6]; /* GIFBYTE array to dump header contents */
+ GIFBYTE LSDDump[7]; /* Logical Screen Descriptor dump */
} GIFHEAD;
-
/*
** The GIF Image Descriptor.
*/
typedef struct _GifImageDescriptor {
- GIFWORD ImageWidth; /* Width of the image in pixels */
- GIFWORD ImageHeight; /* Height of the image in pixels */
- GIFBYTE PackedField; /* Image and Color Table Data Information */
+ GIFWORD ImageWidth; /* Width of the image in pixels */
+ GIFWORD ImageHeight; /* Height of the image in pixels */
+ GIFBYTE PackedField; /* Image and Color Table Data Information */
GIFWORD TableSize;
- GIFWORD CodeSize; /* Minimum LZW CodeSize for image data */
+ GIFWORD CodeSize; /* Minimum LZW CodeSize for image data */
GIFBYTE HDFPalette[256][3];
- GIFBYTE GIDDump[9]; /* GifImageDescriptor dump */
+ GIFBYTE GIDDump[9]; /* GifImageDescriptor dump */
- GIFBYTE *Image; /* Decompressed Raster Image */
+ GIFBYTE *Image; /* Decompressed Raster Image */
GIFBYTE *GIFImage;
} GIFIMAGEDESC;
@@ -91,36 +90,35 @@ typedef struct _GifImageDescriptor {
** GIF 89a Graphic Control Extension Block
*/
typedef struct _GifGraphicControlExtension {
- GIFBYTE GCEDump[5]; /* Graphic Control Extension Dump */
+ GIFBYTE GCEDump[5]; /* Graphic Control Extension Dump */
} GIFGRAPHICCONTROL;
/*
** GIF 89a Plain Text Extension Block
*/
typedef struct _GifPlainTextExtension {
- GIFBYTE PTEDump[15]; /* Plain Text Extension Dump */
- GIFBYTE *PlainTextData; /* Plain Text data sub-blocks */
- GIFWORD DataSize;
+ GIFBYTE PTEDump[15]; /* Plain Text Extension Dump */
+ GIFBYTE *PlainTextData; /* Plain Text data sub-blocks */
+ GIFWORD DataSize;
} GIFPLAINTEXT;
-
/*
** GIF 89a Application Extension Block
*/
typedef struct _GifApplicationExtension {
- GIFBYTE AEDump[14]; /* Application Extension Dump */
- GIFBYTE *ApplicationData; /* Application data sub-blocks */
- GIFWORD DataSize;
+ GIFBYTE AEDump[14]; /* Application Extension Dump */
+ GIFBYTE *ApplicationData; /* Application data sub-blocks */
+ GIFWORD DataSize;
} GIFAPPLICATION;
/*
** GIF 89a Comment Extension Block
*/
typedef struct _GifCommentExtension {
- GIFBYTE CEDump[2]; /* Comment Extension Dump */
- GIFBYTE *CommentData; /* Comment data sub-blocks */
- GIFWORD DataSize;
- GIFBYTE Terminator; /* Block Terminator (always 0) */
+ GIFBYTE CEDump[2]; /* Comment Extension Dump */
+ GIFBYTE *CommentData; /* Comment data sub-blocks */
+ GIFWORD DataSize;
+ GIFBYTE Terminator; /* Block Terminator (always 0) */
} GIFCOMMENT;
/*
@@ -135,12 +133,12 @@ typedef struct _GifCommentExtension {
** extension.
*/
typedef struct _GifToMem {
- GIFHEAD *GifHeader;
- GIFIMAGEDESC **GifImageDesc;
+ GIFHEAD * GifHeader;
+ GIFIMAGEDESC ** GifImageDesc;
GIFGRAPHICCONTROL **GifGraphicControlExtension;
- GIFPLAINTEXT **GifPlainTextExtension;
- GIFAPPLICATION **GifApplicationExtension;
- GIFCOMMENT **GifCommentExtension;
+ GIFPLAINTEXT ** GifPlainTextExtension;
+ GIFAPPLICATION ** GifApplicationExtension;
+ GIFCOMMENT ** GifCommentExtension;
} GIFTOMEM;
/*
@@ -159,12 +157,11 @@ int ReadGifApplication(GIFAPPLICATION *, GIFBYTE **);
int ReadGifComment(GIFCOMMENT *, GIFBYTE **);
/* HDFGIFWR.C */
-int hdfWriteGIF(FILE *fp, GIFBYTE *pic, int ptype, int w, int h, GIFBYTE *rmap,
- GIFBYTE *gmap, GIFBYTE *bmap, GIFBYTE *pc2ncmap, int numcols,
- int colorstyle, int BitsPerPixel);
+int hdfWriteGIF(FILE *fp, GIFBYTE *pic, int ptype, int w, int h, GIFBYTE *rmap, GIFBYTE *gmap, GIFBYTE *bmap,
+ GIFBYTE *pc2ncmap, int numcols, int colorstyle, int BitsPerPixel);
/* WRITEHDF.C */
-int WriteHDF(GIFTOMEM , GIFCHAR * );
+int WriteHDF(GIFTOMEM, GIFCHAR *);
/* Function: ReadHDF
** Return: 0 on completion without error, -1 on error
@@ -175,13 +172,13 @@ int WriteHDF(GIFTOMEM , GIFCHAR * );
** GIFBYTE palette[256][3] - the corresponding palette
** hsize_t* image_size - the size of each dimension of the image
*/
-int ReadHDF(GIFBYTE** data, GIFBYTE palette[256][3], hsize_t *image_size,
- GIFCHAR *h5_file, GIFCHAR *dset_name, GIFCHAR *pal_name);
+int ReadHDF(GIFBYTE **data, GIFBYTE palette[256][3], hsize_t *image_size, GIFCHAR *h5_file,
+ GIFCHAR *dset_name, GIFCHAR *pal_name);
GIFBYTE *Decompress(GIFIMAGEDESC *, GIFHEAD *);
-GIFBYTE GetByte(GIFBYTE *);
-GIFWORD GetWord(GIFBYTE *);
+GIFBYTE GetByte(GIFBYTE *);
+GIFWORD GetWord(GIFBYTE *);
-void cleanup(GIFBYTE*);
+void cleanup(GIFBYTE *);
-#endif /* GIF_H_ */
+#endif /* GIF_H_ */
diff --git a/hl/tools/gif2h5/gif2hdf.c b/hl/tools/gif2h5/gif2hdf.c
index 051ff56..939844c 100644
--- a/hl/tools/gif2h5/gif2hdf.c
+++ b/hl/tools/gif2h5/gif2hdf.c
@@ -18,11 +18,10 @@
#include "h5tools.h"
#include "h5tools_utils.h"
-
int
-main(int argv , char *argc[])
+main(int argv, char *argc[])
{
- GIFTOMEM GifMemoryStruct;
+ GIFTOMEM GifMemoryStruct;
GIFIMAGEDESC gifImageDesc;
FILE *fpGif;
@@ -51,11 +50,9 @@ main(int argv , char *argc[])
/* Initialize h5tools lib */
h5tools_init();
- if ( argc[1] && (strcmp("-V",argc[1])==0) )
- {
+ if (argc[1] && (strcmp("-V", argc[1]) == 0)) {
print_version("gif2h5");
exit(EXIT_SUCCESS);
-
}
if (argv < 3) {
@@ -68,15 +65,15 @@ main(int argv , char *argc[])
GIFFileName = argc[1];
HDFFileName = argc[2];
- if (!(fpGif = fopen(GIFFileName,"rb"))) {
+ if (!(fpGif = fopen(GIFFileName, "rb"))) {
printf("Unable to open GIF file for reading.\n");
exit(EXIT_FAILURE);
}
/* Get the whole file into memory. Mem's much faster than I/O */
- fseek(fpGif, 0L , 2);
+ fseek(fpGif, 0L, 2);
filesize = ftell(fpGif);
- fseek(fpGif, 0L , 0);
+ fseek(fpGif, 0L, 0);
if (filesize == 0)
printf("File Size Zero");
@@ -86,12 +83,12 @@ main(int argv , char *argc[])
exit(EXIT_FAILURE);
}
- if (fread(MemGif,(size_t)filesize,1,fpGif) != 1) {
+ if (fread(MemGif, (size_t)filesize, 1, fpGif) != 1) {
printf("Corrupted Input File");
exit(EXIT_FAILURE);
}
- fseek(fpGif,0L,0);
+ fseek(fpGif, 0L, 0);
/*
* Call Gif2Mem and break the whole file into parts. Gif2Mem also calls
@@ -100,8 +97,8 @@ main(int argv , char *argc[])
Gif2Mem(MemGif, &GifMemoryStruct);
if (ferror(fpGif)) {
- printf("File Stream Error\n\n");
- exit(EXIT_FAILURE);
+ printf("File Stream Error\n\n");
+ exit(EXIT_FAILURE);
}
fclose(fpGif);
@@ -110,54 +107,47 @@ main(int argv , char *argc[])
* Call WriteHDF from here. Go ahead and change WriteHDF to write whatever
* format you want
*/
- if (WriteHDF(GifMemoryStruct , HDFFileName))
+ if (WriteHDF(GifMemoryStruct, HDFFileName))
printf("HDF Write Error\n\n");
/* Free all buffers */
/* replacing int32 with long */
ImageCount = (long)((GifMemoryStruct.GifHeader)->ImageCount);
- for(i = 0; i < ImageCount ; i++) {
+ for (i = 0; i < ImageCount; i++) {
gifImageDesc = *(GifMemoryStruct.GifImageDesc[i]);
if (gifImageDesc.Image != NULL)
free(gifImageDesc.Image);
- if (GifMemoryStruct.GifImageDesc[i] != NULL)
- {
+ if (GifMemoryStruct.GifImageDesc[i] != NULL) {
free(GifMemoryStruct.GifImageDesc[i]);
GifMemoryStruct.GifImageDesc[i] = NULL;
}
- if (GifMemoryStruct.GifGraphicControlExtension[i] != NULL)
- {
+ if (GifMemoryStruct.GifGraphicControlExtension[i] != NULL) {
free(GifMemoryStruct.GifGraphicControlExtension[i]);
GifMemoryStruct.GifGraphicControlExtension[i] = NULL;
}
}
free(StartPos);
- if (GifMemoryStruct.GifHeader != NULL)
- {
+ if (GifMemoryStruct.GifHeader != NULL) {
free(GifMemoryStruct.GifHeader);
GifMemoryStruct.GifHeader = NULL;
}
- if (GifMemoryStruct.GifApplicationExtension != NULL)
- {
+ if (GifMemoryStruct.GifApplicationExtension != NULL) {
free(GifMemoryStruct.GifApplicationExtension);
GifMemoryStruct.GifApplicationExtension = NULL;
}
- if (GifMemoryStruct.GifImageDesc != NULL)
- {
+ if (GifMemoryStruct.GifImageDesc != NULL) {
free(GifMemoryStruct.GifImageDesc);
GifMemoryStruct.GifImageDesc = NULL;
}
- if (GifMemoryStruct.GifGraphicControlExtension != NULL)
- {
+ if (GifMemoryStruct.GifGraphicControlExtension != NULL) {
free(GifMemoryStruct.GifGraphicControlExtension);
GifMemoryStruct.GifGraphicControlExtension = NULL;
}
-
return EXIT_SUCCESS;
}
diff --git a/hl/tools/gif2h5/gif2mem.c b/hl/tools/gif2h5/gif2mem.c
index ae0a113..b1ea718 100644
--- a/hl/tools/gif2h5/gif2mem.c
+++ b/hl/tools/gif2h5/gif2mem.c
@@ -42,29 +42,29 @@ Gif2Mem(GIFBYTE *MemGif, GIFTOMEM *GifMemoryStruct)
* The gif structure outline for passing data to memory is given in gif.h.
* These pointers are redunant, should take them out in ver. 2
*/
- GIFHEAD *gifHead; /* GIF Header structure */
- GIFIMAGEDESC **gifImageDesc; /* Logical Image Descriptor struct */
- GIFPLAINTEXT **gifPlainText; /* Plain Text Extension structure */
- GIFAPPLICATION **gifApplication; /* Application Extension structure */
- GIFCOMMENT **gifComment; /* Comment Extension structure */
+ GIFHEAD * gifHead; /* GIF Header structure */
+ GIFIMAGEDESC ** gifImageDesc; /* Logical Image Descriptor struct */
+ GIFPLAINTEXT ** gifPlainText; /* Plain Text Extension structure */
+ GIFAPPLICATION ** gifApplication; /* Application Extension structure */
+ GIFCOMMENT ** gifComment; /* Comment Extension structure */
GIFGRAPHICCONTROL **gifGraphicControl; /* Graphic Control Extension strct */
- register GIFWORD i; /* Loop counter */
- GIFBYTE Identifier; /* Extension block identifier holder */
- GIFBYTE Label; /* Extension block label holder */
- GIFBYTE ImageCount; /* Count of the number of images in the file */
- GIFBYTE ImageArray; /* Keep the size of the array to store Images */
- GIFBYTE CommentCount;
- GIFBYTE CommentArray;
- GIFBYTE ApplicationCount;
- GIFBYTE ApplicationArray;
- GIFBYTE PlainTextCount;
- GIFBYTE PlainTextArray;
- GIFBYTE GCEflag;
- GIFBYTE aTemp;
- GIFBYTE j;
- GIFBYTE w; /* Two more variables needed only while testing */
- GIFBYTE *b; /* Endian Ordering */
+ register GIFWORD i; /* Loop counter */
+ GIFBYTE Identifier; /* Extension block identifier holder */
+ GIFBYTE Label; /* Extension block label holder */
+ GIFBYTE ImageCount; /* Count of the number of images in the file */
+ GIFBYTE ImageArray; /* Keep the size of the array to store Images */
+ GIFBYTE CommentCount;
+ GIFBYTE CommentArray;
+ GIFBYTE ApplicationCount;
+ GIFBYTE ApplicationArray;
+ GIFBYTE PlainTextCount;
+ GIFBYTE PlainTextArray;
+ GIFBYTE GCEflag;
+ GIFBYTE aTemp;
+ GIFBYTE j;
+ GIFBYTE w; /* Two more variables needed only while testing */
+ GIFBYTE * b; /* Endian Ordering */
/* Allocate memory for the GIF structures */
/* Plug the structs into GifMemoryStruct at the end */
@@ -89,8 +89,8 @@ Gif2Mem(GIFBYTE *MemGif, GIFTOMEM *GifMemoryStruct)
/******************************/
/* Carry out Endian Testing and set Endian Order */
- w = 0x0001;
- b = (GIFBYTE *) &w;
+ w = 0x0001;
+ b = (GIFBYTE *)&w;
EndianOrder = (b[0] ? 1 : 0);
/* Read the GIF image file header information */
@@ -103,22 +103,22 @@ Gif2Mem(GIFBYTE *MemGif, GIFTOMEM *GifMemoryStruct)
fputs("GIFHEAD: Error reading header information!\n", stderr);
exit(EXIT_FAILURE);
}
-#endif /* 0 */
+#endif /* 0 */
/*
* Identify, read, and display block information.
*/
- ImageCount = ImageArray = 0;
- CommentCount = CommentArray = 0;
+ ImageCount = ImageArray = 0;
+ CommentCount = CommentArray = 0;
ApplicationCount = ApplicationArray = 0;
- PlainTextCount = PlainTextArray = 0;
- GCEflag = 0;
+ PlainTextCount = PlainTextArray = 0;
+ GCEflag = 0;
for (;;) {
Identifier = *MemGif++;
switch (Identifier) {
- case 0x3B: /* Trailer */
+ case 0x3B: /* Trailer */
/*
* The counts are stored to make it easier while putting stuff
* into the HDF file and then deallocating space.
@@ -129,17 +129,17 @@ Gif2Mem(GIFBYTE *MemGif, GIFTOMEM *GifMemoryStruct)
gifHead->PlainTextCount = PlainTextCount;
/* putting stuff into the gif2mem structure */
- GifMemoryStruct->GifHeader = gifHead;
- GifMemoryStruct->GifImageDesc = gifImageDesc;
- GifMemoryStruct->GifPlainTextExtension = gifPlainText;
- GifMemoryStruct->GifApplicationExtension = gifApplication;
- GifMemoryStruct->GifCommentExtension = gifComment;
+ GifMemoryStruct->GifHeader = gifHead;
+ GifMemoryStruct->GifImageDesc = gifImageDesc;
+ GifMemoryStruct->GifPlainTextExtension = gifPlainText;
+ GifMemoryStruct->GifApplicationExtension = gifApplication;
+ GifMemoryStruct->GifCommentExtension = gifComment;
GifMemoryStruct->GifGraphicControlExtension = gifGraphicControl;
/* return the struct */
return 0;
- case 0x2C: /* Image Descriptor */
+ case 0x2C: /* Image Descriptor */
/*
* If there was no image descriptor before this increase image
* count. If an imagedescriptor was present, reset GCEflag
@@ -150,40 +150,37 @@ Gif2Mem(GIFBYTE *MemGif, GIFTOMEM *GifMemoryStruct)
GCEflag = 0;
if (ImageCount > ImageArray) {
- aTemp = ImageArray;
+ aTemp = ImageArray;
ImageArray = (GIFBYTE)((ImageArray << 1) + 1);
- if (!(gifImageDesc = (GIFIMAGEDESC **)realloc(gifImageDesc,
- sizeof(GIFIMAGEDESC *) * ImageArray))) {
+ if (!(gifImageDesc =
+ (GIFIMAGEDESC **)realloc(gifImageDesc, sizeof(GIFIMAGEDESC *) * ImageArray))) {
printf("Out of memory!");
exit(EXIT_FAILURE);
}
if (!(gifGraphicControl = (GIFGRAPHICCONTROL **)realloc(
- gifGraphicControl,
- sizeof(GIFGRAPHICCONTROL *) * ImageArray))) {
+ gifGraphicControl, sizeof(GIFGRAPHICCONTROL *) * ImageArray))) {
printf("Out of memory!");
exit(EXIT_FAILURE);
}
- for (j = aTemp ; j < ImageArray ; j++) {
+ for (j = aTemp; j < ImageArray; j++) {
gifGraphicControl[j] = NULL;
- gifImageDesc[j] = NULL;
+ gifImageDesc[j] = NULL;
}
}
- if(!(gifImageDesc[ImageCount-1] = (GIFIMAGEDESC*)malloc(sizeof(GIFIMAGEDESC)))) {
+ if (!(gifImageDesc[ImageCount - 1] = (GIFIMAGEDESC *)malloc(sizeof(GIFIMAGEDESC)))) {
printf("Out of memory!");
exit(EXIT_FAILURE);
}
-
- if (ReadGifImageDesc(gifImageDesc[ImageCount-1], &MemGif) == -1)
+ if (ReadGifImageDesc(gifImageDesc[ImageCount - 1], &MemGif) == -1)
fputs("Error reading Image Descriptor information\n", stderr);
/* Decompress the Image */
- gifImageDesc[ImageCount-1]->Image = Decompress(gifImageDesc[ImageCount-1],
- gifHead);
- free(gifImageDesc[ImageCount-1]->GIFImage);
+ gifImageDesc[ImageCount - 1]->Image = Decompress(gifImageDesc[ImageCount - 1], gifHead);
+ free(gifImageDesc[ImageCount - 1]->GIFImage);
/*
* Convert the local palette into an HDF compatible palette In
@@ -191,150 +188,146 @@ Gif2Mem(GIFBYTE *MemGif, GIFTOMEM *GifMemoryStruct)
* the HDFPalette If it is absent the global table is written
* as the HDFPalette.
*/
- if (!((gifImageDesc[ImageCount-1]->PackedField) & 0x80)) {
+ if (!((gifImageDesc[ImageCount - 1]->PackedField) & 0x80)) {
/* Check to see if the global color table exists.... */
if (gifHead->PackedField & 0x80) {
- for (i=0 ; i<gifHead->TableSize ; i++) {
- gifImageDesc[ImageCount-1]->HDFPalette[i][0] =
- gifHead->HDFPalette[i][0];
- gifImageDesc[ImageCount-1]->HDFPalette[i][1] =
- gifHead->HDFPalette[i][1];
- gifImageDesc[ImageCount-1]->HDFPalette[i][2] =
- gifHead->HDFPalette[i][2];
+ for (i = 0; i < gifHead->TableSize; i++) {
+ gifImageDesc[ImageCount - 1]->HDFPalette[i][0] = gifHead->HDFPalette[i][0];
+ gifImageDesc[ImageCount - 1]->HDFPalette[i][1] = gifHead->HDFPalette[i][1];
+ gifImageDesc[ImageCount - 1]->HDFPalette[i][2] = gifHead->HDFPalette[i][2];
}
}
- gifImageDesc[ImageCount-1]->TableSize = gifHead->TableSize;
+ gifImageDesc[ImageCount - 1]->TableSize = gifHead->TableSize;
}
break;
- case 0x21: /* Extension Block */
- Label = *MemGif++;
+ case 0x21: /* Extension Block */
+ Label = *MemGif++;
- switch (Label) {
- case 0x01: /* Plain Text Extension */
+ switch (Label) {
+ case 0x01: /* Plain Text Extension */
puts("Plain Text Extension\n");
PlainTextCount++;
if (PlainTextCount > PlainTextArray)
PlainTextArray = (GIFBYTE)((PlainTextArray << 1) + 1);
- if (!(gifPlainText = (GIFPLAINTEXT **)realloc(gifPlainText , sizeof(GIFPLAINTEXT *) * PlainTextArray))) {
+ if (!(gifPlainText = (GIFPLAINTEXT **)realloc(gifPlainText, sizeof(GIFPLAINTEXT *) *
+ PlainTextArray))) {
printf("Out of memory!");
exit(EXIT_FAILURE);
}
- if(!(gifPlainText[PlainTextCount - 1] = (GIFPLAINTEXT*)malloc(sizeof(GIFPLAINTEXT)))) {
+ if (!(gifPlainText[PlainTextCount - 1] =
+ (GIFPLAINTEXT *)malloc(sizeof(GIFPLAINTEXT)))) {
printf("Out of memory!");
exit(EXIT_FAILURE);
}
if (ReadGifPlainText(gifPlainText[PlainTextCount - 1], &MemGif))
- fprintf(stderr,
- "Error reading Plain Text Extension information.\n");
+ fprintf(stderr, "Error reading Plain Text Extension information.\n");
break;
- case 0xFE: /* Comment Extension */
+ case 0xFE: /* Comment Extension */
CommentCount++;
if (CommentCount > CommentArray)
CommentArray = (GIFBYTE)((CommentArray << 1) + 1);
- if (!(gifComment = (GIFCOMMENT **)realloc(gifComment , sizeof(GIFCOMMENT *) * CommentArray))) {
+ if (!(gifComment =
+ (GIFCOMMENT **)realloc(gifComment, sizeof(GIFCOMMENT *) * CommentArray))) {
printf("Out of memory!");
exit(EXIT_FAILURE);
}
- if(!(gifComment[CommentCount - 1] = (GIFCOMMENT *)malloc(sizeof(GIFCOMMENT)))) {
+ if (!(gifComment[CommentCount - 1] = (GIFCOMMENT *)malloc(sizeof(GIFCOMMENT)))) {
printf("Out of memory!");
exit(EXIT_FAILURE);
}
-
if (ReadGifComment(gifComment[CommentCount - 1], &MemGif))
- fprintf(stderr,
- "Error reading Comment Extension information\n");
+ fprintf(stderr, "Error reading Comment Extension information\n");
break;
- case 0xF9: /* Graphic Control Extension */
- if (GCEflag == 0 )
+ case 0xF9: /* Graphic Control Extension */
+ if (GCEflag == 0)
ImageCount++;
GCEflag = 1;
if (ImageCount > ImageArray) {
- aTemp = ImageArray;
+ aTemp = ImageArray;
ImageArray = (GIFBYTE)((ImageArray << 1) + 1);
- if (!(gifGraphicControl = (GIFGRAPHICCONTROL **)realloc(gifGraphicControl , sizeof(GIFGRAPHICCONTROL *) * ImageArray))) {
+ if (!(gifGraphicControl = (GIFGRAPHICCONTROL **)realloc(
+ gifGraphicControl, sizeof(GIFGRAPHICCONTROL *) * ImageArray))) {
printf("Out of memory!");
exit(EXIT_FAILURE);
}
- if (!(gifImageDesc = (GIFIMAGEDESC **)realloc(gifImageDesc , sizeof(GIFIMAGEDESC *) * ImageArray))) {
+ if (!(gifImageDesc = (GIFIMAGEDESC **)realloc(
+ gifImageDesc, sizeof(GIFIMAGEDESC *) * ImageArray))) {
printf("Out of memory!");
exit(EXIT_FAILURE);
}
- for (j = aTemp ; j < ImageArray ; j++) {
+ for (j = aTemp; j < ImageArray; j++) {
gifGraphicControl[j] = NULL;
gifImageDesc[j] = NULL;
}
}
- if(!(gifGraphicControl[ImageCount-1] = (GIFGRAPHICCONTROL*)malloc(sizeof(GIFGRAPHICCONTROL)))) {
+ if (!(gifGraphicControl[ImageCount - 1] =
+ (GIFGRAPHICCONTROL *)malloc(sizeof(GIFGRAPHICCONTROL)))) {
printf("Out of memory!");
exit(EXIT_FAILURE);
}
-
- if (ReadGifGraphicControl(gifGraphicControl[ImageCount-1], &MemGif))
- fprintf(stderr,
- "Error reading Graphic Control Extension information\n");
+ if (ReadGifGraphicControl(gifGraphicControl[ImageCount - 1], &MemGif))
+ fprintf(stderr, "Error reading Graphic Control Extension information\n");
(*MemGif)++;
if ((!*MemGif) == 0)
- fprintf(stderr,
- "Error reading Graphic Control Extension\n");
+ fprintf(stderr, "Error reading Graphic Control Extension\n");
break;
- case 0xFF: /* Application Extension */
+ case 0xFF: /* Application Extension */
ApplicationCount++;
if (ApplicationCount > ApplicationArray)
ApplicationArray = (GIFBYTE)((ApplicationArray << 1) + 1);
- if (!(gifApplication = (GIFAPPLICATION **)realloc(gifApplication , sizeof(GIFAPPLICATION *) * ApplicationArray))) {
+ if (!(gifApplication = (GIFAPPLICATION **)realloc(
+ gifApplication, sizeof(GIFAPPLICATION *) * ApplicationArray))) {
printf("Out of memory!");
exit(EXIT_FAILURE);
}
- if(!(gifApplication[ApplicationCount - 1] = (GIFAPPLICATION *)malloc(sizeof(GIFAPPLICATION)))) {
+ if (!(gifApplication[ApplicationCount - 1] =
+ (GIFAPPLICATION *)malloc(sizeof(GIFAPPLICATION)))) {
printf("Out of memory!");
exit(EXIT_FAILURE);
}
-
if (ReadGifApplication(gifApplication[ApplicationCount - 1], &MemGif))
- fprintf(stderr,
- "Error reading Application Extension information\n");
+ fprintf(stderr, "Error reading Application Extension information\n");
break;
default:
printf("Unknown Extension Label: %#02x\n", Label);
break;
- }
+ }
- break;
+ break;
default:
- fprintf(stderr,
- "Unknown Block Separator Character: %#02x\n", Identifier);
+ fprintf(stderr, "Unknown Block Separator Character: %#02x\n", Identifier);
}
}
}
diff --git a/hl/tools/gif2h5/gifread.c b/hl/tools/gif2h5/gifread.c
index 79671aa..705e6f3 100644
--- a/hl/tools/gif2h5/gifread.c
+++ b/hl/tools/gif2h5/gifread.c
@@ -26,21 +26,19 @@ GetWord(GIFBYTE *MemGif)
if (EndianOrder == 1) {
/* LittleEndian */
- w = (GIFWORD) (*MemGif++ & 0xFF);
- w |= (GIFWORD) ((*MemGif++ & 0xFF) << 0x08);
- } else {
- w = (GIFWORD) (*MemGif++ & 0xFF);
- w = ((GIFWORD) (*MemGif++ & 0xFF)) | (w << 0x08);
+ w = (GIFWORD)(*MemGif++ & 0xFF);
+ w |= (GIFWORD)((*MemGif++ & 0xFF) << 0x08);
+ }
+ else {
+ w = (GIFWORD)(*MemGif++ & 0xFF);
+ w = ((GIFWORD)(*MemGif++ & 0xFF)) | (w << 0x08);
}
return w;
}
GIFBYTE
-GetByte(GIFBYTE *MemGif)
-{
- return *MemGif;
-}
+GetByte(GIFBYTE *MemGif) { return *MemGif; }
/*
* Read a GIF image GIFBYTE Header.
@@ -53,23 +51,23 @@ GetByte(GIFBYTE *MemGif)
* otherwise 0 if no error occured.
*/
int
-ReadGifHeader(GIFHEAD *GifHead, /* Pointer to GIF header structure */
- GIFBYTE **MemGif2) /* GIF image file input FILE stream */
+ReadGifHeader(GIFHEAD * GifHead, /* Pointer to GIF header structure */
+ GIFBYTE **MemGif2) /* GIF image file input FILE stream */
{
- GIFWORD i; /* Loop counter */
- GIFWORD tableSize; /* Number of entires in the Global Color Table */
+ GIFWORD i; /* Loop counter */
+ GIFWORD tableSize; /* Number of entires in the Global Color Table */
GifHead->TableSize = 0;
- for (i = 0 ; i < 6 ; i++) {
+ for (i = 0; i < 6; i++) {
GifHead->HeaderDump[i] = *(*MemGif2)++;
}
- if (strncmp((const char *)GifHead->HeaderDump , "GIF" , (size_t)3)) {
+ if (strncmp((const char *)GifHead->HeaderDump, "GIF", (size_t)3)) {
printf("The file does not appear to be a valid GIF file.\n");
exit(EXIT_FAILURE);
}
- for (i = 0 ; i < 7 ; i++) {
+ for (i = 0; i < 7; i++) {
GifHead->LSDDump[i] = *(*MemGif2)++;
}
@@ -78,7 +76,7 @@ ReadGifHeader(GIFHEAD *GifHead, /* Pointer to GIF header structure */
/* Check if a Global Color Table is present */
if (GifHead->PackedField & 0x80) {
/* Read number of color table entries */
- tableSize = (GIFWORD) (1L << ((GifHead->PackedField & 0x07) + 1));
+ tableSize = (GIFWORD)(1L << ((GifHead->PackedField & 0x07) + 1));
GifHead->TableSize = tableSize;
/* Read the Global Color Table */
@@ -100,12 +98,11 @@ ReadGifHeader(GIFHEAD *GifHead, /* Pointer to GIF header structure */
#if 0
if (ferror(FpGif))
return -1;
-#endif /* 0 */
+#endif /* 0 */
- return 0; /* No FILE stream error occured */
+ return 0; /* No FILE stream error occured */
}
-
/*
** Read a GIF Local Image Descriptor.
**
@@ -120,93 +117,85 @@ ReadGifHeader(GIFHEAD *GifHead, /* Pointer to GIF header structure */
** otherwise 0 if no error occured.
*/
int
-ReadGifImageDesc(
- GIFIMAGEDESC *GifImageDesc, /* Pointer to GIF image descriptor structure */
- GIFBYTE **MemGif2 /* GIF image file input FILE stream */
- )
+ReadGifImageDesc(GIFIMAGEDESC *GifImageDesc, /* Pointer to GIF image descriptor structure */
+ GIFBYTE ** MemGif2 /* GIF image file input FILE stream */
+)
{
- GIFWORD i; /* Loop counter */
- GIFWORD tableSize; /* Number of entries in the Local Color Table */
- /* GIFBYTE Interlace; */ /* PackedField & 0x20 gives information on interlacing */
- GIFBYTE *TempPtr;
- int ch , ch1;
-
- GifImageDesc->TableSize = 0;
- for (i = 0 ; i < 9 ; i++) {
- GifImageDesc->GIDDump[i] = *(*MemGif2)++;
- }
-
- /*
- ** Get the relevant fields. I need ImageWidth and Height actively hence I have
- ** taken information from those fields. I intend to keep the GifImageDesc data
- ** structure as it is so that anyone needing the rest of the fields can do so
- ** quickly.
- */
-
- if (EndianOrder == 1) /* LittleEndian */
- {
- GifImageDesc->ImageWidth = (GIFWORD) (GifImageDesc->GIDDump[4] & 0xFF);
- GifImageDesc->ImageWidth |= (GIFWORD) ((GifImageDesc->GIDDump[5] & 0xFF) << 0x08);
-
- GifImageDesc->ImageHeight = (GIFWORD) (GifImageDesc->GIDDump[6] & 0xFF);
- GifImageDesc->ImageHeight |= (GIFWORD) ((GifImageDesc->GIDDump[7] & 0xFF) << 0x08);
-
- }
- else
- {
- GifImageDesc->ImageWidth = (GIFWORD) (GifImageDesc->GIDDump[4] & 0xFF);
- GifImageDesc->ImageWidth = ((GIFWORD) (GifImageDesc->GIDDump[5] & 0xFF)) | (GifImageDesc->ImageWidth << 0x08);
+ GIFWORD i; /* Loop counter */
+ GIFWORD tableSize; /* Number of entries in the Local Color Table */
+ /* GIFBYTE Interlace; */ /* PackedField & 0x20 gives information on interlacing */
+ GIFBYTE *TempPtr;
+ int ch, ch1;
+
+ GifImageDesc->TableSize = 0;
+ for (i = 0; i < 9; i++) {
+ GifImageDesc->GIDDump[i] = *(*MemGif2)++;
+ }
- GifImageDesc->ImageHeight = (GIFWORD) (GifImageDesc->GIDDump[6] & 0xFF);
- GifImageDesc->ImageHeight = ((GIFWORD) (GifImageDesc->GIDDump[7] & 0xFF)) | (GifImageDesc->ImageWidth << 0x08);
+ /*
+ ** Get the relevant fields. I need ImageWidth and Height actively hence I have
+ ** taken information from those fields. I intend to keep the GifImageDesc data
+ ** structure as it is so that anyone needing the rest of the fields can do so
+ ** quickly.
+ */
+ if (EndianOrder == 1) /* LittleEndian */
+ {
+ GifImageDesc->ImageWidth = (GIFWORD)(GifImageDesc->GIDDump[4] & 0xFF);
+ GifImageDesc->ImageWidth |= (GIFWORD)((GifImageDesc->GIDDump[5] & 0xFF) << 0x08);
- }
+ GifImageDesc->ImageHeight = (GIFWORD)(GifImageDesc->GIDDump[6] & 0xFF);
+ GifImageDesc->ImageHeight |= (GIFWORD)((GifImageDesc->GIDDump[7] & 0xFF) << 0x08);
+ }
+ else {
+ GifImageDesc->ImageWidth = (GIFWORD)(GifImageDesc->GIDDump[4] & 0xFF);
+ GifImageDesc->ImageWidth =
+ ((GIFWORD)(GifImageDesc->GIDDump[5] & 0xFF)) | (GifImageDesc->ImageWidth << 0x08);
+
+ GifImageDesc->ImageHeight = (GIFWORD)(GifImageDesc->GIDDump[6] & 0xFF);
+ GifImageDesc->ImageHeight =
+ ((GIFWORD)(GifImageDesc->GIDDump[7] & 0xFF)) | (GifImageDesc->ImageWidth << 0x08);
+ }
- GifImageDesc->PackedField = GifImageDesc->GIDDump[8];
+ GifImageDesc->PackedField = GifImageDesc->GIDDump[8];
- /* Interlace = GifImageDesc->PackedField & 0x20; */
+ /* Interlace = GifImageDesc->PackedField & 0x20; */
/* Check if a Local Color Table is present */
- if (GifImageDesc->PackedField & 0x80)
- {
+ if (GifImageDesc->PackedField & 0x80) {
/* Read number of color table entries */
- tableSize = (GIFWORD) (1L << ((GifImageDesc->PackedField & 0x07) + 1));
- GifImageDesc->TableSize = tableSize;
+ tableSize = (GIFWORD)(1L << ((GifImageDesc->PackedField & 0x07) + 1));
+ GifImageDesc->TableSize = tableSize;
/* Read the Local Color Table */
- for (i = 0; i < tableSize; i++)
- {
+ for (i = 0; i < tableSize; i++) {
GifImageDesc->HDFPalette[i][0] = *(*MemGif2)++;
GifImageDesc->HDFPalette[i][1] = *(*MemGif2)++;
GifImageDesc->HDFPalette[i][2] = *(*MemGif2)++;
}
}
- /*
- ** Get LZW minimum Code Size
- */
- GifImageDesc->CodeSize = (GIFWORD)*(*MemGif2)++;
-
- /*GifImageDesc->GIFImage = ReadDataSubBlocks(FpGif);*/
- if (!(GifImageDesc->GIFImage = (GIFBYTE *)malloc((GifImageDesc->ImageWidth) * (GifImageDesc->ImageHeight)))) {
- printf("Out of memory");
- exit(EXIT_FAILURE);
- }
-
-
- TempPtr = GifImageDesc->GIFImage;
- do
- {
- ch = ch1 = (int)*(*MemGif2)++;
- while (ch--) *TempPtr++ = *(*MemGif2)++;
- }
- while (ch1);
+ /*
+ ** Get LZW minimum Code Size
+ */
+ GifImageDesc->CodeSize = (GIFWORD) * (*MemGif2)++;
+
+ /*GifImageDesc->GIFImage = ReadDataSubBlocks(FpGif);*/
+ if (!(GifImageDesc->GIFImage =
+ (GIFBYTE *)malloc((GifImageDesc->ImageWidth) * (GifImageDesc->ImageHeight)))) {
+ printf("Out of memory");
+ exit(EXIT_FAILURE);
+ }
+ TempPtr = GifImageDesc->GIFImage;
+ do {
+ ch = ch1 = (int)*(*MemGif2)++;
+ while (ch--)
+ *TempPtr++ = *(*MemGif2)++;
+ } while (ch1);
- return(0); /* No FILE stream error occured */
+ return (0); /* No FILE stream error occured */
}
-
/*
** Read a GIF Graphic Control Extension block.
**
@@ -217,21 +206,19 @@ ReadGifImageDesc(
** otherwise 0 if no error occured.
*/
int
-ReadGifGraphicControl(
- GIFGRAPHICCONTROL *GifGraphicControl, /* Pointer to GC Extension structure */
- GIFBYTE **MemGif2 /* GIF image file input FILE stream */
- )
+ReadGifGraphicControl(GIFGRAPHICCONTROL *GifGraphicControl, /* Pointer to GC Extension structure */
+ GIFBYTE ** MemGif2 /* GIF image file input FILE stream */
+)
{
int i;
- for (i = 0 ; i < 5 ; i++) {
- GifGraphicControl->GCEDump[i] = *(*MemGif2)++;
+ for (i = 0; i < 5; i++) {
+ GifGraphicControl->GCEDump[i] = *(*MemGif2)++;
}
- return(0); /* No FILE stream error occured */
+ return (0); /* No FILE stream error occured */
}
-
/*
** Read a GIF Plain Text Extension block.
**
@@ -242,35 +229,33 @@ ReadGifGraphicControl(
** otherwise 0 if no error occured.
*/
int
-ReadGifPlainText(
- GIFPLAINTEXT *GifPlainText, /* Pointer to Plain Text Extension structure */
- GIFBYTE **MemGif2 /* GIF image file input FILE stream */
- )
+ReadGifPlainText(GIFPLAINTEXT *GifPlainText, /* Pointer to Plain Text Extension structure */
+ GIFBYTE ** MemGif2 /* GIF image file input FILE stream */
+)
{
int i;
- for (i = 0 ; i < 13 ; i++) {
- GifPlainText->PTEDump[i] = *(*MemGif2)++;
- }
+ for (i = 0; i < 13; i++) {
+ GifPlainText->PTEDump[i] = *(*MemGif2)++;
+ }
/* Read in the Plain Text data sub-blocks */
- if (!(GifPlainText->PlainTextData = ReadDataSubBlocks(MemGif2 , &(GifPlainText->DataSize))))
- return(1);
+ if (!(GifPlainText->PlainTextData = ReadDataSubBlocks(MemGif2, &(GifPlainText->DataSize))))
+ return (1);
/*
GifPlainText->Terminator = 0;
*/
/* Check for a FILE stream error */
- /*
- if (ferror(FpGif))
- return(-1);
- */
+ /*
+ if (ferror(FpGif))
+ return(-1);
+ */
- return(0); /* No FILE stream error occured */
+ return (0); /* No FILE stream error occured */
}
-
/*
** Read a GIF Application Extension block.
**
@@ -281,34 +266,32 @@ ReadGifPlainText(
** otherwise 0 if no error occured.
*/
int
-ReadGifApplication(
- GIFAPPLICATION *GifApplication, /* Pointer to Application Extension structure */
- GIFBYTE **MemGif2 /* GIF image file input FILE stream */
- )
+ReadGifApplication(GIFAPPLICATION *GifApplication, /* Pointer to Application Extension structure */
+ GIFBYTE ** MemGif2 /* GIF image file input FILE stream */
+)
{
int i;
- for (i = 0 ; i < 12 ; i++) {
- GifApplication->AEDump[i] = *(*MemGif2)++;
- }
+ for (i = 0; i < 12; i++) {
+ GifApplication->AEDump[i] = *(*MemGif2)++;
+ }
/* Read in the Plain Text data sub-blocks */
- if (!(GifApplication->ApplicationData = ReadDataSubBlocks(MemGif2 , &(GifApplication->DataSize))))
- return(1);
- /*
- GifApplication->Terminator = 0;
- */
+ if (!(GifApplication->ApplicationData = ReadDataSubBlocks(MemGif2, &(GifApplication->DataSize))))
+ return (1);
+ /*
+ GifApplication->Terminator = 0;
+ */
- /* Check for a FILE stream error */
- /*
- if (ferror(FpGif))
- return(-1);
- */
+ /* Check for a FILE stream error */
+ /*
+ if (ferror(FpGif))
+ return(-1);
+ */
- return(0); /* No FILE stream error occured */
+ return (0); /* No FILE stream error occured */
}
-
/*
** Read a GIF Comment Extension block.
**
@@ -319,22 +302,20 @@ ReadGifApplication(
** otherwise 0 if no error occured.
*/
int
-ReadGifComment(
- GIFCOMMENT *GifComment, /* Pointer to GIF Comment Extension structure */
- GIFBYTE **MemGif2 /* GIF image file input FILE stream */
- )
+ReadGifComment(GIFCOMMENT *GifComment, /* Pointer to GIF Comment Extension structure */
+ GIFBYTE ** MemGif2 /* GIF image file input FILE stream */
+)
{
/* Read in the Plain Text data sub-blocks */
- if (!(GifComment->CommentData = ReadDataSubBlocks(MemGif2 , &(GifComment->DataSize))))
- return(1);
+ if (!(GifComment->CommentData = ReadDataSubBlocks(MemGif2, &(GifComment->DataSize))))
+ return (1);
GifComment->Terminator = 0;
- return(0); /* No FILE stream error occured */
+ return (0); /* No FILE stream error occured */
}
-
/*
** Read one or more GIF data sub-blocks and write the information
** to a buffer.
@@ -347,55 +328,47 @@ ReadGifComment(
*/
static GIFBYTE *
ReadDataSubBlocks(GIFBYTE **MemGif2, /* GIF image file input FILE stream */
- GIFWORD *DSize)
+ GIFWORD * DSize)
{
GIFBYTE *ptr1; /* Pointer used to "walk the heap" */
GIFBYTE *ptr2; /* Pointer used to mark the top of the heap */
- GIFBYTE dataSize; /* Size of the current data sub-block being read */
- GIFWORD bufSize; /* Total size of the Plain Text data buffer */
- int tempcount = 0;
+ GIFBYTE dataSize; /* Size of the current data sub-block being read */
+ GIFWORD bufSize; /* Total size of the Plain Text data buffer */
+ int tempcount = 0;
- bufSize = 0; /* The output buffer is empty */
+ bufSize = 0; /* The output buffer is empty */
- dataSize = *(*MemGif2)++; /* Get the size of the first sub-block */
+ dataSize = *(*MemGif2)++; /* Get the size of the first sub-block */
/* Allocate initial data buffer */
- if (!(ptr1 = ptr2 = (GIFBYTE *) malloc((size_t)dataSize + 1))) {
- printf("Out of memory. Allocation of memory for data sub-blocks for\neither Comment, Plain Text or Application Extensions failed");
- return((GIFBYTE *) NULL);
- }
- for (;;)
- {
- tempcount++;
- bufSize += (dataSize); /* Running total of the buffer size */
- *DSize = bufSize;
+ if (!(ptr1 = ptr2 = (GIFBYTE *)malloc((size_t)dataSize + 1))) {
+ printf("Out of memory. Allocation of memory for data sub-blocks for\neither Comment, Plain Text or "
+ "Application Extensions failed");
+ return ((GIFBYTE *)NULL);
+ }
+ for (;;) {
+ tempcount++;
+ bufSize += (dataSize); /* Running total of the buffer size */
+ *DSize = bufSize;
#ifdef COMMENTED_OUT
- *ptr1++ = dataSize; /* Write the data count */
-#endif /* COMMENTED_OUT */
- while (dataSize--) /* Read/write the Plain Text data */
- *ptr1++ = *(*MemGif2)++;
+ *ptr1++ = dataSize; /* Write the data count */
+#endif /* COMMENTED_OUT */
+ while (dataSize--) /* Read/write the Plain Text data */
+ *ptr1++ = *(*MemGif2)++;
/* Check if there is another data sub-block */
if ((dataSize = *(*MemGif2)++) == 0)
- break; /* Block Terminator encountered */
+ break; /* Block Terminator encountered */
/* Increase the buffer size to accomodate the next sub-block */
- if (!(ptr1 = ptr2 = (GIFBYTE *) realloc(ptr2, bufSize + dataSize + 1)))
- return((GIFBYTE *) NULL);
-
-
- ptr1 += bufSize; /* Move pointer to the end of the data */
-
+ if (!(ptr1 = ptr2 = (GIFBYTE *)realloc(ptr2, bufSize + dataSize + 1)))
+ return ((GIFBYTE *)NULL);
+ ptr1 += bufSize; /* Move pointer to the end of the data */
}
*ptr1++ = '\0';
- return(ptr2); /* Return a pointer to the sub-block data */
+ return (ptr2); /* Return a pointer to the sub-block data */
}
-
-
-
-
-
diff --git a/hl/tools/gif2h5/h52gifgentst.c b/hl/tools/gif2h5/h52gifgentst.c
index 655563c..9bd7874 100644
--- a/hl/tools/gif2h5/h52gifgentst.c
+++ b/hl/tools/gif2h5/h52gifgentst.c
@@ -30,11 +30,11 @@
*/
#define FILENAME "h52giftst.h5"
-#define WIDTH 400
-#define HEIGHT 200
-#define PAL_ENTRIES 256
-#define IMAGE1_NAME "image"
-#define PAL_NAME "palette"
+#define WIDTH 400
+#define HEIGHT 200
+#define PAL_ENTRIES 256
+#define IMAGE1_NAME "image"
+#define PAL_NAME "palette"
/*-------------------------------------------------------------------------
* Function: main
@@ -44,65 +44,61 @@
*-------------------------------------------------------------------------
*/
-int main(void)
+int
+main(void)
{
- hid_t fid;
- int i, j, n, space;
+ hid_t fid;
+ int i, j, n, space;
unsigned char *buf;
- unsigned char pal[ PAL_ENTRIES * 3 ]; /* palette array */
- hsize_t pal_dims[2] = {PAL_ENTRIES,3}; /* palette dimensions */
- hsize_t width = WIDTH;
- hsize_t height = HEIGHT;
+ unsigned char pal[PAL_ENTRIES * 3]; /* palette array */
+ hsize_t pal_dims[2] = {PAL_ENTRIES, 3}; /* palette dimensions */
+ hsize_t width = WIDTH;
+ hsize_t height = HEIGHT;
/* Allocate buffer */
- if(NULL == (buf = (unsigned char *)malloc(WIDTH * HEIGHT)))
+ if (NULL == (buf = (unsigned char *)malloc(WIDTH * HEIGHT)))
return EXIT_FAILURE;
/* create a file */
- if ((fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT))<0)
+ if ((fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
return EXIT_FAILURE;
/* create an image */
- space = WIDTH*HEIGHT / PAL_ENTRIES;
- for (i=0, j=0, n=0; i < WIDTH*HEIGHT; i++, j++ )
- {
+ space = WIDTH * HEIGHT / PAL_ENTRIES;
+ for (i = 0, j = 0, n = 0; i < WIDTH * HEIGHT; i++, j++) {
buf[i] = (unsigned char)n;
- if ( j > space )
- {
+ if (j > space) {
n++;
- j=0;
+ j = 0;
}
-
}
/* make the image */
- if (H5IMmake_image_8bit( fid, IMAGE1_NAME, width, height, buf )<0)
+ if (H5IMmake_image_8bit(fid, IMAGE1_NAME, width, height, buf) < 0)
return EXIT_FAILURE;
- /*-------------------------------------------------------------------------
- * define a palette, blue to red tones
- *-------------------------------------------------------------------------
- */
- for ( i=0, n=0; i<PAL_ENTRIES*3; i+=3, n++)
- {
- pal[i] = (unsigned char)n; /* red */
- pal[i+1] = (unsigned char)0; /* green */
- pal[i+2] = (unsigned char)(255-n); /* blue */
+ /*-------------------------------------------------------------------------
+ * define a palette, blue to red tones
+ *-------------------------------------------------------------------------
+ */
+ for (i = 0, n = 0; i < PAL_ENTRIES * 3; i += 3, n++) {
+ pal[i] = (unsigned char)n; /* red */
+ pal[i + 1] = (unsigned char)0; /* green */
+ pal[i + 2] = (unsigned char)(255 - n); /* blue */
}
/* make a palette */
- if (H5IMmake_palette( fid, PAL_NAME, pal_dims, pal )<0)
+ if (H5IMmake_palette(fid, PAL_NAME, pal_dims, pal) < 0)
return EXIT_FAILURE;
/* attach the palette to the image */
- if (H5IMlink_palette( fid, IMAGE1_NAME, PAL_NAME )<0)
+ if (H5IMlink_palette(fid, IMAGE1_NAME, PAL_NAME) < 0)
return EXIT_FAILURE;
- if(H5Fclose(fid)<0)
+ if (H5Fclose(fid) < 0)
return EXIT_FAILURE;
free(buf);
return EXIT_SUCCESS;
}
-
diff --git a/hl/tools/gif2h5/hdf2gif.c b/hl/tools/gif2h5/hdf2gif.c
index 5633df8..36f1ea1 100644
--- a/hl/tools/gif2h5/hdf2gif.c
+++ b/hl/tools/gif2h5/hdf2gif.c
@@ -18,9 +18,8 @@
#include "h5tools.h"
#include "h5tools_utils.h"
-#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;
@@ -28,8 +27,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
@@ -39,39 +38,39 @@ 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");
-
}
FILE *fpGif = NULL;
-int main(int argc , char **argv)
+int
+main(int argc, char **argv)
{
- GIFBYTE *Image;
- void *edata;
+ GIFBYTE * Image;
+ void * edata;
H5E_auto2_t func;
/* compression structs */
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;
/* Disable error reporting */
H5Eget_auto2(H5E_DEFAULT, &func, &edata);
@@ -80,16 +79,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");
exit(EXIT_SUCCESS);
-
}
-
- if (argc < 4)
- {
+ if (argc < 4) {
/* they didn't supply at least one image -- bail */
usage();
return EXIT_FAILURE;
@@ -99,19 +94,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;
@@ -123,83 +116,74 @@ 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 )
- {
- fprintf(stderr , "Unable to get the palette. Aborting.\n");
+ if (H5IMget_palette(fid, image_name, 0, pal) < 0) {
+ fprintf(stderr, "Unable to get the palette. Aborting.\n");
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);
@@ -210,7 +194,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
@@ -220,62 +203,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;
}
@@ -287,59 +260,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;
}
@@ -352,7 +320,6 @@ int main(int argc , char **argv)
return EXIT_SUCCESS;
-
out:
if (fpGif != NULL)
diff --git a/hl/tools/gif2h5/hdfgifwr.c b/hl/tools/gif2h5/hdfgifwr.c
index ed3e9e9..4619b99 100644
--- a/hl/tools/gif2h5/hdfgifwr.c
+++ b/hl/tools/gif2h5/hdfgifwr.c
@@ -44,7 +44,6 @@
* Joe Orost (decvax!vax135!petsd!joe)
*****************************************************************/
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -65,29 +64,29 @@ static void flush_char(void);
#else
static void compress(), output(), cl_block(), cl_hash();
static void char_init(), char_out(), flush_char();
-#endif /* __STDC__ */
+#endif /* __STDC__ */
static byte pc2nc[256];
/*************************************************************/
-int hdfWriteGIF(FILE *fp, byte *pic, int ptype, int w, int h, byte *rmap,
- byte *gmap, byte *bmap, byte *pc2ncmap, int numcols,
- int colorstyle, int BitsPerPixel)
+int
+hdfWriteGIF(FILE *fp, byte *pic, int ptype, int w, int h, byte *rmap, byte *gmap, byte *bmap, byte *pc2ncmap,
+ int numcols, int colorstyle, int BitsPerPixel)
{
- int InitCodeSize;
- int i;
+ int InitCodeSize;
+ int i;
byte *pic8 = pic;
/* Shut compiler up... */
- ptype=ptype;
- rmap=rmap;
- gmap=gmap;
- bmap=bmap;
- numcols=numcols;
- colorstyle=colorstyle;
+ ptype = ptype;
+ rmap = rmap;
+ gmap = gmap;
+ bmap = bmap;
+ numcols = numcols;
+ colorstyle = colorstyle;
for (i = 0; i < 256; i++) {
- pc2nc[i] = pc2ncmap[i];
+ pc2nc[i] = pc2ncmap[i];
}
if (BitsPerPixel <= 1)
@@ -96,40 +95,40 @@ int hdfWriteGIF(FILE *fp, byte *pic, int ptype, int w, int h, byte *rmap,
InitCodeSize = BitsPerPixel;
if (!fp) {
- fprintf(stderr, "WriteGIF: file not open for writing\n" );
+ fprintf(stderr, "WriteGIF: file not open for writing\n");
return (1);
}
- compress(InitCodeSize+1, fp, pic8, w*h);
+ compress(InitCodeSize + 1, fp, pic8, w * h);
if (ferror(fp))
return -1;
- return 0 ;
+ return 0;
}
/***********************************************************************/
static unsigned long cur_accum = 0;
-static int cur_bits = 0;
+static int cur_bits = 0;
-#define MAXCODE(n_bits) ( (1 << (n_bits)) - 1)
-#define XV_BITS 12 /* BITS was already defined on some systems */
-#define HSIZE 5003 /* 80% occupancy */
+#define MAXCODE(n_bits) ((1 << (n_bits)) - 1)
+#define XV_BITS 12 /* BITS was already defined on some systems */
+#define HSIZE 5003 /* 80% occupancy */
-typedef unsigned char char_type;
+typedef unsigned char char_type;
static int n_bits; /* number of bits/code */
static int maxbits = XV_BITS; /* user settable max # bits/code */
static int maxcode; /* maximum code, given n_bits */
static int maxmaxcode = 1 << XV_BITS; /* NEVER generate this */
-static count_int htab [HSIZE];
-static unsigned short codetab [HSIZE];
+static count_int htab[HSIZE];
+static unsigned short codetab[HSIZE];
-#define HashTabOf(i) htab[i]
-#define CodeTabOf(i) codetab[i]
+#define HashTabOf(i) htab[i]
+#define CodeTabOf(i) codetab[i]
-static int hsize = HSIZE; /* for dynamic table sizing */
+static int hsize = HSIZE; /* for dynamic table sizing */
/*
* To save much memory, we overlay the table used by compress() with those
@@ -140,7 +139,7 @@ static int hsize = HSIZE; /* for dynamic table sizing */
* used to be 8000 characters).
*/
-static int free_ent = 0; /* first unused entry */
+static int free_ent = 0; /* first unused entry */
/*
* block compression parameters -- after all codes are used up,
@@ -148,8 +147,8 @@ static int free_ent = 0; /* first unused entry */
*/
static int clear_flg = 0;
-static long int in_count = 1; /* length of input */
-static long int out_count = 0; /* # of codes output (for debugging) */
+static long int in_count = 1; /* length of input */
+static long int out_count = 0; /* # of codes output (for debugging) */
/*
* compress stdin to stdout
@@ -167,22 +166,23 @@ static long int out_count = 0; /* # of codes output (for debugging) */
* about this implementation to ames!jaw.
*/
-static int g_init_bits;
+static int g_init_bits;
static FILE *g_outfile;
static int ClearCode;
static int EOFCode;
/********************************************************/
-static void compress(int init_bits, FILE *outfile, byte *data, int len)
+static void
+compress(int init_bits, FILE *outfile, byte *data, int len)
{
register long fcode;
- register int i = 0;
- register int c;
- register int ent;
- register int disp;
- register int hsize_reg;
- register int hshift;
+ register int i = 0;
+ register int c;
+ register int ent;
+ register int disp;
+ register int hsize_reg;
+ register int hshift;
/*
* Set up the globals: g_init_bits - initial number of bits g_outfile -
@@ -192,40 +192,40 @@ static void compress(int init_bits, FILE *outfile, byte *data, int len)
g_outfile = outfile;
/* initialize 'compress' globals */
- maxbits = XV_BITS;
- maxmaxcode = 1<<XV_BITS;
+ maxbits = XV_BITS;
+ maxmaxcode = 1 << XV_BITS;
memset(htab, 0, sizeof(htab));
memset(codetab, 0, sizeof(codetab));
- hsize = HSIZE;
- free_ent = 0;
+ hsize = HSIZE;
+ free_ent = 0;
clear_flg = 0;
- in_count = 1;
+ in_count = 1;
out_count = 0;
cur_accum = 0;
- cur_bits = 0;
+ cur_bits = 0;
/* Set up the necessary values */
out_count = 0;
clear_flg = 0;
- in_count = 1;
- maxcode = MAXCODE(n_bits = g_init_bits);
+ in_count = 1;
+ maxcode = MAXCODE(n_bits = g_init_bits);
ClearCode = (1 << (init_bits - 1));
- EOFCode = ClearCode + 1;
- free_ent = ClearCode + 2;
+ EOFCode = ClearCode + 1;
+ free_ent = ClearCode + 2;
char_init();
ent = pc2nc[*data++];
len--;
hshift = 0;
- for (fcode = (long)hsize; fcode < 65536L; fcode *= 2L )
+ for (fcode = (long)hsize; fcode < 65536L; fcode *= 2L)
hshift++;
hshift = 8 - hshift; /* set hash code range bound */
hsize_reg = hsize;
- cl_hash( (count_int) hsize_reg); /* clear hash table */
+ cl_hash((count_int)hsize_reg); /* clear hash table */
output(ClearCode);
@@ -234,32 +234,33 @@ static void compress(int init_bits, FILE *outfile, byte *data, int len)
len--;
in_count++;
- fcode = (long)(((long) c << maxbits) + ent);
- i = (((int) c << hshift) ^ ent); /* xor hashing */
+ fcode = (long)(((long)c << maxbits) + ent);
+ i = (((int)c << hshift) ^ ent); /* xor hashing */
- if ( HashTabOf (i) == fcode ) {
- ent = CodeTabOf (i);
+ if (HashTabOf(i) == fcode) {
+ ent = CodeTabOf(i);
continue;
- } else if ( (long)HashTabOf (i) < 0) {
+ }
+ else if ((long)HashTabOf(i) < 0) {
/* empty slot */
goto nomatch;
}
- disp = hsize_reg - i; /* secondary hash (after G. Knott) */
+ disp = hsize_reg - i; /* secondary hash (after G. Knott) */
- if ( i == 0 )
+ if (i == 0)
disp = 1;
probe:
if ((i -= disp) < 0)
i += hsize_reg;
- if (HashTabOf (i) == fcode) {
- ent = CodeTabOf (i);
+ if (HashTabOf(i) == fcode) {
+ ent = CodeTabOf(i);
continue;
}
- if ((long)HashTabOf (i) >= 0)
+ if ((long)HashTabOf(i) >= 0)
goto probe;
nomatch:
@@ -268,9 +269,10 @@ nomatch:
ent = c;
if (free_ent < maxmaxcode) {
- CodeTabOf (i) = (unsigned short)free_ent++; /* code -> hashtable */
- HashTabOf (i) = fcode;
- } else {
+ CodeTabOf(i) = (unsigned short)free_ent++; /* code -> hashtable */
+ HashTabOf(i) = fcode;
+ }
+ else {
cl_block();
}
}
@@ -281,7 +283,6 @@ nomatch:
output(EOFCode);
}
-
/*****************************************************************
* TAG( output )
*
@@ -299,11 +300,8 @@ nomatch:
* code in turn. When the buffer fills up empty it and start over.
*/
-static
-unsigned long masks[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F,
- 0x001F, 0x003F, 0x007F, 0x00FF,
- 0x01FF, 0x03FF, 0x07FF, 0x0FFF,
- 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF };
+static unsigned long masks[] = {0x0000, 0x0001, 0x0003, 0x0007, 0x000F, 0x001F, 0x003F, 0x007F, 0x00FF,
+ 0x01FF, 0x03FF, 0x07FF, 0x0FFF, 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF};
static void
output(int code)
@@ -317,8 +315,8 @@ output(int code)
cur_bits += n_bits;
- while( cur_bits >= 8 ) {
- char_out( (int)((unsigned int) cur_accum & 0xff) );
+ while (cur_bits >= 8) {
+ char_out((int)((unsigned int)cur_accum & 0xff));
cur_accum >>= 8;
cur_bits -= 8;
}
@@ -329,12 +327,13 @@ output(int code)
*/
if (free_ent > maxcode || clear_flg) {
if (clear_flg) {
- maxcode = MAXCODE (n_bits = g_init_bits);
+ maxcode = MAXCODE(n_bits = g_init_bits);
clear_flg = 0;
- } else {
+ }
+ else {
n_bits++;
- if ( n_bits == maxbits )
+ if (n_bits == maxbits)
maxcode = maxmaxcode;
else
maxcode = MAXCODE(n_bits);
@@ -343,17 +342,17 @@ output(int code)
if (code == EOFCode) {
/* At EOF, write the rest of the buffer */
- while( cur_bits > 0 ) {
- char_out( (int)((unsigned int)cur_accum & 0xff) );
+ while (cur_bits > 0) {
+ char_out((int)((unsigned int)cur_accum & 0xff));
cur_accum >>= 8;
cur_bits -= 8;
}
flush_char();
- fflush( g_outfile );
+ fflush(g_outfile);
#ifdef FOO
- if(ferror( g_outfile))
+ if (ferror(g_outfile))
FatalError("unable to write GIF file");
#endif
}
@@ -361,45 +360,45 @@ output(int code)
/********************************/
static void
-cl_block(void) /* table clear for block compress */
+cl_block(void) /* table clear for block compress */
{
/* Clear out the hash table */
- cl_hash((count_int) hsize);
- free_ent = ClearCode + 2;
+ cl_hash((count_int)hsize);
+ free_ent = ClearCode + 2;
clear_flg = 1;
output(ClearCode);
}
/********************************/
static void
-cl_hash(count_int hashsize) /* reset code table */
+cl_hash(count_int hashsize) /* reset code table */
{
- count_int *htab_p = htab+hashsize;
- long i, m1 = -1;
+ count_int *htab_p = htab + hashsize;
+ long i, m1 = -1;
i = hashsize - 16;
- do { /* might use Sys V memset(3) here */
- *(htab_p-16) = m1;
- *(htab_p-15) = m1;
- *(htab_p-14) = m1;
- *(htab_p-13) = m1;
- *(htab_p-12) = m1;
- *(htab_p-11) = m1;
- *(htab_p-10) = m1;
- *(htab_p-9) = m1;
- *(htab_p-8) = m1;
- *(htab_p-7) = m1;
- *(htab_p-6) = m1;
- *(htab_p-5) = m1;
- *(htab_p-4) = m1;
- *(htab_p-3) = m1;
- *(htab_p-2) = m1;
- *(htab_p-1) = m1;
+ do { /* might use Sys V memset(3) here */
+ *(htab_p - 16) = m1;
+ *(htab_p - 15) = m1;
+ *(htab_p - 14) = m1;
+ *(htab_p - 13) = m1;
+ *(htab_p - 12) = m1;
+ *(htab_p - 11) = m1;
+ *(htab_p - 10) = m1;
+ *(htab_p - 9) = m1;
+ *(htab_p - 8) = m1;
+ *(htab_p - 7) = m1;
+ *(htab_p - 6) = m1;
+ *(htab_p - 5) = m1;
+ *(htab_p - 4) = m1;
+ *(htab_p - 3) = m1;
+ *(htab_p - 2) = m1;
+ *(htab_p - 1) = m1;
htab_p -= 16;
} while ((i -= 16) >= 0);
- for ( i += 16; i > 0; i-- )
+ for (i += 16; i > 0; i--)
*--htab_p = m1;
}
@@ -426,7 +425,7 @@ char_init(void)
/*
* Define the storage for the packet accumulator
*/
-static char accum[ 256 ];
+static char accum[256];
/*
* Add a character to the end of the current packet, and if it is 254
@@ -435,7 +434,7 @@ static char accum[ 256 ];
static void
char_out(int c)
{
- accum[ a_count++ ] = (char)c;
+ accum[a_count++] = (char)c;
if (a_count >= 254)
flush_char();
@@ -448,8 +447,8 @@ static void
flush_char(void)
{
if (a_count > 0) {
- fputc( a_count, g_outfile );
- fwrite( accum, (size_t)1, (size_t)a_count, g_outfile);
+ fputc(a_count, g_outfile);
+ fwrite(accum, (size_t)1, (size_t)a_count, g_outfile);
a_count = 0;
}
}
diff --git a/hl/tools/gif2h5/writehdf.c b/hl/tools/gif2h5/writehdf.c
index c2933c5..0cf3926 100644
--- a/hl/tools/gif2h5/writehdf.c
+++ b/hl/tools/gif2h5/writehdf.c
@@ -37,21 +37,21 @@
int
WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName)
{
- GIFHEAD gifHead; /* GIF Header structure */
- GIFIMAGEDESC *gifImageDesc; /* Logical Image Descriptor struct */
- int has_pal=0;
+ GIFHEAD gifHead; /* GIF Header structure */
+ GIFIMAGEDESC *gifImageDesc; /* Logical Image Descriptor struct */
+ int has_pal = 0;
- long ImageCount; /* number of images */
+ long ImageCount; /* number of images */
#ifdef UNUSED
- long CommentCount, /* number of comments */
- ApplicationCount, /* number of application extensions */
- PlainTextCount; /* number of plain text extensions */
-#endif /* UNUSED */
+ long CommentCount, /* number of comments */
+ ApplicationCount, /* number of application extensions */
+ PlainTextCount; /* number of plain text extensions */
+#endif /* UNUSED */
- char ImageName[256]; /* Image name for the Image */
+ char ImageName[256]; /* Image name for the Image */
/* H5 variables */
- hid_t file_id; /* H5 file id */
+ hid_t file_id; /* H5 file id */
/* temp counter */
int i;
@@ -62,35 +62,36 @@ WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName)
/* get some data from gifHead */
ImageCount = gifHead.ImageCount;
#ifdef UNUSED
- CommentCount = (GIFWORD)gifHead.CommentCount;
+ CommentCount = (GIFWORD)gifHead.CommentCount;
ApplicationCount = (GIFWORD)gifHead.ApplicationCount;
- PlainTextCount = (GIFWORD)gifHead.PlainTextCount;
+ PlainTextCount = (GIFWORD)gifHead.PlainTextCount;
#endif /* UNUSED */
- if ((file_id = H5Fcreate(HDFName , H5F_ACC_TRUNC , H5P_DEFAULT , H5P_DEFAULT)) < 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");
- fprintf(stderr , "NOTE: GIF file must be present in the same directory as the binary on UNIX systems.\n");
+ 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 */
- hsize_t dims[2]; /* specify the dimensions of the palette */
+ hsize_t dims[2]; /* specify the dimensions of the palette */
/* size of the palette is tablesize (rows) X 3 (columns) */
dims[0] = gifHead.TableSize;
dims[1] = 3;
/* make a palette */
- if (H5IMmake_palette(file_id,PAL_NAME,dims,(unsigned char *)gifHead.HDFPalette)<0)
- return -1;
+ if (H5IMmake_palette(file_id, PAL_NAME, dims, (unsigned char *)gifHead.HDFPalette) < 0)
+ return -1;
- has_pal=1;
+ has_pal = 1;
}
- for(i = 0; i < ImageCount; i++) {
- hsize_t dims[2]; /* dimensions for the dataset */
+ for (i = 0; i < ImageCount; i++) {
+ hsize_t dims[2]; /* dimensions for the dataset */
/* get the gifImageDesc */
gifImageDesc = GifMemoryStruct.GifImageDesc[i];
@@ -99,26 +100,24 @@ WriteHDF(GIFTOMEM GifMemoryStruct, char *HDFName)
dims[1] = gifImageDesc->ImageWidth;
/* create the image name */
- sprintf(ImageName , "Image%d" , i);
+ sprintf(ImageName, "Image%d", i);
/* write image */
- if (H5IMmake_image_8bit(file_id,ImageName,dims[1],dims[0],(gifImageDesc->Image))<0)
- return -1;
+ if (H5IMmake_image_8bit(file_id, ImageName, dims[1], dims[0], (gifImageDesc->Image)) < 0)
+ return -1;
/* attach the palette to the image dataset */
- if (has_pal)
- {
- if (H5IMlink_palette(file_id,ImageName,PAL_NAME)<0)
+ if (has_pal) {
+ if (H5IMlink_palette(file_id, ImageName, PAL_NAME) < 0)
return -1;
}
}
/* close the H5 file */
if (H5Fclose(file_id) < 0) {
- fprintf(stderr , "Could not close HDF5 file. Aborting...\n");
+ fprintf(stderr, "Could not close HDF5 file. Aborting...\n");
return -1;
}
return 0;
}
-