diff options
author | Larry Knox <lrknox@hdfgroup.org> | 2020-10-16 22:47:27 (GMT) |
---|---|---|
committer | Larry Knox <lrknox@hdfgroup.org> | 2020-10-16 22:47:27 (GMT) |
commit | db30c2da68ece4a155e9e50c28ec16d6057509b2 (patch) | |
tree | 1d36f673c36dfee71c266bba39511da21ecc782e /hl/tools/gif2h5/decompress.c | |
parent | 5b9cf732caab9daa6ed1e00f2df4f5a792340196 (diff) | |
parent | 2e2b87d1cbdee3b919e6e5cba6c5ecd1b9434434 (diff) | |
download | hdf5-db30c2da68ece4a155e9e50c28ec16d6057509b2.zip hdf5-db30c2da68ece4a155e9e50c28ec16d6057509b2.tar.gz hdf5-db30c2da68ece4a155e9e50c28ec16d6057509b2.tar.bz2 |
Merge HDF5 1.10.7 release files into 1.10/masterhdf5-1_10_7
Diffstat (limited to 'hl/tools/gif2h5/decompress.c')
-rw-r--r-- | hl/tools/gif2h5/decompress.c | 75 |
1 files changed, 46 insertions, 29 deletions
diff --git a/hl/tools/gif2h5/decompress.c b/hl/tools/gif2h5/decompress.c index 6668c22..129fa60 100644 --- a/hl/tools/gif2h5/decompress.c +++ b/hl/tools/gif2h5/decompress.c @@ -15,13 +15,13 @@ #include "gif.h" -WORD iWIDE, iHIGH, eWIDE, eHIGH, expand, numcols, strip, nostrip; +GIFWORD iWIDE, iHIGH, eWIDE, eHIGH, expand, numcols, strip, nostrip; unsigned long cols[256]; char *cmd; FILE *fp; -static WORD +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 */ @@ -29,7 +29,7 @@ static WORD IWidth, IHeight; /* image dimensions */ static int BitOffset = 0, /* Bit Offset of next code */ - Pass = 0, /* Used by output routine if WORDerlaced pic */ + 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 */ @@ -43,26 +43,26 @@ static int ReadMask; /* Code AND mask for current code size */ /*MODIFICATIONS*/ -BYTE tempbyte[10]; -BYTE * tempBYTEptr[10]; -WORD tempint[10]; -WORD ImageCount = 0; +GIFBYTE tempbyte[10]; +GIFBYTE * tempGIFBYTEptr[10]; +GIFWORD tempint[10]; +GIFWORD ImageCount = 0; /*END MODIFICATION*/ boolean Interlace, HasColormap; -BYTE *Image; /* The result array */ -BYTE *RawGIF; /* The heap array to hold it, raw */ -BYTE *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 */ -int Prefix[4096]; -int Suffix[4096]; +int *Prefix; +int *Suffix; /* An output array used by the decompressor */ -int OutCode[1025]; +int *OutCode; /* The color map, read from the GIF header */ @@ -70,10 +70,10 @@ int numused; /* * Fetch the next code from the raster data stream. The codes can be any - * length from 3 to 12 bits, packed WORDo 8-bit BYTEs, so we have to maWORDain - * our location in the Raster array as a BIT Offset. We compute the BYTE - * Offset WORDo the raster array by dividing this by 8, pick up three BYTEs, - * compute the bit Offset WORDo our 24-bit chunk, shift to bring the desired + * length from 3 to 12 bits, packed into 8-bit GIFBYTEs, so we have to maintain + * our location in the Raster array as a BIT Offset. We compute the GIFBYTE + * Offset into the raster array by dividing this by 8, pick up three GIFBYTEs, + * compute the bit Offset into our 24-bit chunk, shift to bring the desired * code to the bottom, then mask it off and return it. */ static int @@ -93,7 +93,7 @@ ReadCode(void) } static void -AddToPixel(BYTE Index) +AddToPixel(GIFBYTE Index) { if (YC<IHeight) *(Image + YC * BytesPerScanline + XC) = Index; @@ -104,8 +104,8 @@ AddToPixel(BYTE Index) * Y-coordinate */ if (++XC == IWidth) { /* - * If a non-WORDerlaced picture, just increment YC to the next scan - * line. If it's WORDerlaced, deal with the WORDerlace as described + * If a non-interlaced picture, just increment YC to the next scan + * line. If it's interlaced, deal with the interlace as described * in the GIF spec. Put the decoded scan line out to the screen if we * haven't gone past the bottom of it. */ @@ -154,11 +154,24 @@ AddToPixel(BYTE Index) /* Main routine. Convert a GIF image to an HDF image */ -BYTE * +GIFBYTE * Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) { int i; + if (!(Prefix = calloc(4096, sizeof(int)))) { + printf("Out of memory"); + exit(EXIT_FAILURE); + } + if (!(Suffix = calloc(4096, sizeof(int)))) { + printf("Out of memory"); + exit(EXIT_FAILURE); + } + if (!(OutCode = calloc(1024, sizeof(int)))) { + printf("Out of memory"); + exit(EXIT_FAILURE); + } + XC = 0; YC = 0; Pass = 0; @@ -173,7 +186,7 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) /* Now read in values from the image descriptor */ IWidth = GifImageDesc->ImageWidth; IHeight = GifImageDesc->ImageHeight; - Interlace = GifImageDesc->PackedField & 0x40; + Interlace = (uint8_t)(GifImageDesc->PackedField & 0x40); /* * Note that I ignore the possible existence of a local color map. I'm @@ -183,7 +196,7 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) */ /* - * Start reading the raster data. First we get the WORDial code size and + * Start reading the raster data. First we get the intial code size and * compute decompressor constant values, based on this code size. */ @@ -206,13 +219,13 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) /* * Read the raster data. Here we just transpose it from the GIF array to - * the Raster array, turning it from a series of blocks WORDo one long + * the Raster array, turning it from a series of blocks into one long * data stream, which makes life much easier for ReadCode(). */ /* Allocate the Image */ - if (!(Image = (BYTE *)malloc((size_t)IWidth*(size_t)IHeight))) { + if (!(Image = (GIFBYTE *)malloc((size_t)IWidth*(size_t)IHeight))) { printf("Out of memory"); exit(EXIT_FAILURE); } @@ -238,7 +251,7 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) FreeCode = FirstFree; CurCode = OldCode = Code = ReadCode(); FinChar = CurCode & DataMask; - AddToPixel((BYTE)FinChar); + AddToPixel((GIFBYTE)FinChar); } else { /* * If not a clear code, then must be data: save same as CurCode @@ -256,7 +269,7 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) } /* - * Unless this code is raw data, pursue the chain poWORDed to by + * Unless this code is raw data, pursue the chain pointed to by * CurCode through the hash table to its end; each code in the * chain puts its associated output code on the output queue. */ @@ -278,7 +291,7 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) * stacked LIFO, so deal with it that way... */ for (i = OutCount - 1; i >= 0; i--) - AddToPixel((BYTE)OutCode[i]); + AddToPixel((GIFBYTE)OutCode[i]); OutCount = 0; @@ -291,7 +304,7 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) OldCode = InCode; /* - * PoWORD to the next slot in the table. If we exceed the current + * Point to the next slot in the table. If we exceed the current * MaxCode value, increment the code size unless it's already 12. * If it is, do nothing: the next code decompressed better be * CLEAR @@ -309,5 +322,9 @@ Decompress(GIFIMAGEDESC *GifImageDesc, GIFHEAD *GifHead) Code = ReadCode(); } + free(Prefix); + free(Suffix); + free(OutCode); + return Image; } |