gif.ss: GIF and Animated GIF Writing

To load: (require (lib "gif.ss" "mrlib"))

The gif.ss library provides functions for writing bitmap objects to GIF files.

(write-gif bitmap filename)      PROCEDURE

Writes the given bitmap to filename as a GIF image, where bitmap is either an instance of bitmap% or a thunk (to be called just once) that generates such an object. If the bitmap uses more than 256 colors, it is automatically quantized using a simple algorithm. If the bitmap has a mask bitmap, it is used to determine transparent pixels in the generated GIF image.

(write-animated-gif bitmap-list delay filename [#:one-at-a-time? one-at-a-time?])      PROCEDURE

Writes the bitmaps in bitmap-list to filename as an animated GIF. The bitmap-list list can contain a mixture of bitmap% objects and thunks (each called just once) that produce bitmap% objects. The delay argument is the amount of time in 1/100s of a second to wait between transitions.

If on-at-a-time? is #f (the default), then the content of all images is collected and quantized at once, to produce a single colortable; a drawback to this approach is that it uses more memory, and it allows less color variation among animation frames. Even when on-at-a-time? is false, the result of each thunk in bitmap-list is converted to a byte-string one at a time (which helps avoid bitmap-count limits under Windows).

If on-at-a-time? is true, then the bitmaps are quantized and written to the file one at a time; that is, for each thunk in bitmap-list, its result is written and discarded before another thunk is called. A drawback to this approach is that a separate colortable is written for each frame in the animation, which can make the resulting file large.