Chan-Vese Segmentation
Functions
gifwrite.h File Reference

Write animated GIF files. More...

Go to the source code of this file.

Functions

int GifWrite (unsigned char **Image, int ImageWidth, int ImageHeight, int NumFrames, const unsigned char *Palette, int NumColors, int TransparentColor, const int *Delays, const char *OutputFile)
 Write an animated GIF image. More...
 
void FrameDifference (unsigned char **Image, int ImageWidth, int ImageHeight, int NumFrames, int TransparentColor)
 Optimize animation frames by setting unchanged pixels to transparent. More...
 

Detailed Description

Write animated GIF files.

Author
Pascal Getreuer getre.nosp@m.uer@.nosp@m.gmail.nosp@m..com

Copyright (c) 2011, Pascal Getreuer All rights reserved.

This program is free software: you can redistribute it and/or modify it under, at your option, the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version, or the terms of the simplified BSD license.

You should have received a copy of these licenses along with this program. If not, see http://www.gnu.org/licenses/ and http://www.opensource.org/licenses/bsd-license.html.

Definition in file gifwrite.h.

Function Documentation

void FrameDifference ( unsigned char **  Image,
int  ImageWidth,
int  ImageHeight,
int  NumFrames,
int  TransparentColor 
)

Optimize animation frames by setting unchanged pixels to transparent.

Parameters
Imagearray holding the image data for each frame
ImageWidth,ImageHeightdimensions of the image
NumFramesnumber of frames
Palette(global) color palette used by all the frames
NumColorsnumber of colors in Palette
TransparentColorindex of which color is transparent
Delaysthe delay for each frame in centiseconds
OutputFilefilename of the output GIF file

Definition at line 401 of file gifwrite.c.

int GifWrite ( unsigned char **  Image,
int  ImageWidth,
int  ImageHeight,
int  NumFrames,
const unsigned char *  Palette,
int  NumColors,
int  TransparentColor,
const int *  Delays,
const char *  OutputFile 
)

Write an animated GIF image.

Parameters
Imagearray holding the image data for each frame
ImageWidth,ImageHeightdimensions of the image
NumFramesnumber of frames
Palette(global) color palette used by all the frames
NumColorsnumber of colors in Palette
TransparentColorindex of which color is transparent
Delaysthe delay for each frame in centiseconds
OutputFilefilename of the output GIF file
Returns
1 on success, 0 on failure

This routine writes a sequence of image frames as an animated GIF file. Image should be an array of pointers where Image[k] points to image data in row-major order for the kth frame,

Image[k][x + ImageWidth*y] = pixel at (x,y) in the kth frame.

The value of Image[k][x + ImageWidth*y] is the palette index of the pixel's color. Palette should be ordered such that

Palette[3*i + 0] = red intensity of the ith color,
Palette[3*i + 1] = green intensity of the ith color,
Palette[3*i + 2] = blue intensity of the ith color,

where i = 0, 1, ... NumColors - 1. TransparentColor specifies an index to denote transparent pixels.

This routine always uses the overwrite "frame disposal" method, which means that the current frame is drawn on top of the previous ones. This approach allows animated frames to be transparent everywhere except for the pixels that differ from the preceding frame. Call the FrameDifference() function before GifWrite() to perform this optimization.

Delays is an array specifying how long each frame of the animation is shown in units of centiseconds (1/100th of a second). Specifying Delays as NULL sets a delay of 0.1 seconds per frame.

Only a limited portion of the GIF specification is implemented. Particularly,

  • transparency is always used (GIF does not require this)
  • local color tables are not supported
  • the frame disposal method is hardcoded to overwrite
  • the background color index is hardcoded to 0

See [1] for details on the GIF format.

For LZW compression, we follow the hash table algorithm used in GIFCSRC [2] and the UNIX "compress" program [3]. The hash table uses open addressing double hashing (no chaining) on the prefix code / next character combination and a variant of Knuth's algorithm D (vol. 3, sec. 6.4) with G. Knott's relatively-prime secondary probe.

References: [1] http://www.w3.org/Graphics/GIF/spec-gif89a.txt [2] http://www.programmersheaven.com/download/15257/download.aspx [3] http://www.freebsd.org/cgi/cvsweb.cgi/src/usr.bin/compress/

Definition at line 120 of file gifwrite.c.