All patents concerning the GIF file format have expired (http://lpf.ai.mit.edu/Patents/Gif/Gif.html). To celebrate it, I have programmed a pair of functions loadGIF and saveGIF to use them with Intel(R) OpenCV libraries (read and write GIFs to IplImage, respectively). The code is based on Whirlgif Revision 3.04. The package just contains two files: opencvgif.h (definition of functions loadGIF and saveGIF) and opencvgif.cpp (implementations).
IplImage *loadGIF (const char *name);
The function loadGIF loads an image from the specified GIF file and returns the pointer to the loaded image. If the image cannot be loaded, it returns NULL. Otherwise, the image has always 3 channels (i.e. the palette is applied, even though the palette is grayscale). GIF87a and GIF89a are supported. If the file contains an animated GIF, the first frame of the file is loaded.
int saveGIF (const char *name, IplImage *img);
The function saveGIF saves the image to the specified GIF file. Only 8U-bit single-channel or 3-channel (with 'BGR' channel order) images can be saved using this function. In the first case, a grayscale palette is used. In the second case, a fixed palette is used, with 3 bits for red, 3 bits for green, and 2 bits for blue. A simple dithering algorithm is applied. On error, the function returns 0, otherwise 1.
(c) 2005, by Gines Garcia Mateos
This software may be freely copied, modified and redistributed for both non-commercial and commercial use, without fee provided that this copyright notice is preserved intact on all copies and modified copies.
This library is based on:
Revision 3.04 (http://www.danbbs.dk/~dino/whirlgif/)
There is no warranty or other guarantee of fitness of this software. It is provided solely "as is". The author(s) disclaim(s) all responsibility and liability with respect to this software's usage or its effect upon hardware or computer systems.
The Graphics Interchange format (c) is the Copyright property of Compuserve Incorporated. Gif(sm) is a Service Mark property of Compuserve Incorporated.
Last modification: 10/3/2006