summaryrefslogtreecommitdiffstats
path: root/hl/tools/gif2h5/gifread.c
diff options
context:
space:
mode:
authorAllen Byrne <byrn@hdfgroup.org>2020-09-30 14:27:10 (GMT)
committerAllen Byrne <byrn@hdfgroup.org>2020-09-30 14:27:10 (GMT)
commitb2d661b508a7fc7a2592c13bc6bdc175551f075d (patch)
tree13baeb0d83a7c2a4c6299993c182b1227c2f6114 /hl/tools/gif2h5/gifread.c
parent29ab58b58dce556639ea3154e262895773a8a8df (diff)
downloadhdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.zip
hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.gz
hdf5-b2d661b508a7fc7a2592c13bc6bdc175551f075d.tar.bz2
Clang-format of source files
Diffstat (limited to 'hl/tools/gif2h5/gifread.c')
-rw-r--r--hl/tools/gif2h5/gifread.c311
1 files changed, 142 insertions, 169 deletions
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 */
}
-
-
-
-
-