Tutorial

This is a quick start guide to the library.

Step 1 - GIF Data

First of all, you will need to specify what GIF data to use. This is defined by the lpGIFData and dwGIFDataSize members of the GIF_INFO structure. Create a new GIF_INFO structure:

.data?
TestGif GIF_INFO <>

Now you will have to fill the lpGIFData and dwGIFDataSize members of this structure. Set the values manually to some pointer, use GIFLoadResource or GIFLoadFile:

;manually
push somepointertogifdata
pop TestGif.lpGIFData
push sizeofsomegifdata
pop TestGif.dwDataSize

;or with GIFLoadResource (loads GIF data from a resource)
invoke GetModuleHandle, NULL
mov hInstance, eax
invoke GIFLoadResource, ADDR TestGif, hInstance, ID_GIFRESOURCE

;or width GIFLoadFile (loads GIF data from a file)
.data
GifFilename db "testimage.gif",0
.code
invoke GIFLoadFile, ADDR TestGif, ADDR GifFilename


Step 2 - Load header

Now load the GIF header width GIFLoadHeader

invoke GIFLoadHeader, ADDR TestGif

The GIFVersion, dwLSWidth and dwLSHeight members of TestGif are now set. This function should be called before using GIFInitializeDecoder or GIFDecompress.


Step 3 - Initialize decoder

Before using the decoder, you should initialize it:

invoke GIFInitializeDecoder, ADDR TestGif

The dwImageWidth, dwImageHeight, lpColorTable and ColorCount members of TestGif are set. This function should be called before using GIFDecompress.


Step 4 - Set image format etc.

You will now need to set an image format and an output buffer. The image format (dwImageFormat) can be IMAGEFORMAT_1BIT, IMAGEFORMAT_4BIT or IMAGEFORMAT_8BIT. A higher color format than the original gif may be used, lower is not allowed (see functions for more information). You can set the color format manually or use the minimum (i.e. the one that creates the smallest output) color format by using the return value of GIFGetMinimumColorType:

;manually
mov TestGif.dwImageFormat, IMAGEFORMAT_4BIT

;or automatically
invoke GIFGetMinimumColorType, ADDR TestGif
mov TestGif.dwImageFormat, eax

If you want to create a bitmap from it, use GIFFillBitmapInfoStruct to get a valid BITMAPINFOHEADER structure. Note that if you use a function like CreateDIBitmap, the color table should immediatly follow the BITMAPINFOHEADER structure (BITMAPINFO format).

.data?
BitmapInfoHeader BITMAPINFOHEADER <>
.code
invoke GIFFillBitmapInfoStruct, ADDR TestGif, ADDR BitmapInfoHeader

Now set the lpImageData member to a valid pointer to a buffer that's big enough to store the bitmap image (If you are using CreateDIBitmap, this buffer is created by windows for you). You can get the nr of bytes needed with GIFGetOutputSize:

invoke GIFGetOutputSize, ADDR TestGif
; ......
; create a buffer with size eax
; ......

mov TestGif.lpImageData, {pointer to buffer}


Step 5 - Decompress

GIFDecompress will decode the GIF with all the given parameters in the GIF_INFO structure:

invoke GIFDecompress, ADDR TestGif


Step 6- Cleanup

As the final step, cleanup the allocated memory:

invoke GIFCleanup, ADDR TestGif