image.decoders.gif #
============================================================================Constants
fn decode #
fn decode(data []u8) !common.Image
decode decodes the first GIF frame into a top-down RGBA image.
fn decode_animation #
fn decode_animation(data []u8) !common.Animation
decode_animation coalesces every GIF frame into a viewer-ready animation.
fn new_gif_player #
fn new_gif_player(data []u8) !&GifPlayer
new_gif_player parses the GIF header/block stream (fast) and prepares an empty canvas. No frame pixels are decoded until step() is called.
struct GifPlayer #
struct GifPlayer {
pub mut:
width int
height int
mut:
d GifDecoder
canvas []u8
snapbuf []u8
index int
has_pending bool
pmethod int
prect Rect
}
GifPlayer decodes and composites GIF frames one at a time onto a persistent canvas, instead of coalescing every frame up front. This keeps GIF loading O(1) per navigation (parse + one frame) so a large animated GIF never blocks the UI thread, and it avoids holding every frame's RGBA in memory at once.
Frames must be stepped in order (0, 1, 2, ...). When a loop restarts, call reset() to clear the canvas before stepping frame 0 again. The disposal bookkeeping mirrors coalesce() exactly.
fn (GifPlayer) frame_count #
fn (p &GifPlayer) frame_count() int
frame_count returns the number of frames in the GIF.
fn (GifPlayer) canvas_width #
fn (p &GifPlayer) canvas_width() int
canvas_width returns the GIF canvas width (interface parity with the viewer's AnimPlayer).
fn (GifPlayer) canvas_height #
fn (p &GifPlayer) canvas_height() int
canvas_height returns the GIF canvas height (interface parity with the viewer's AnimPlayer).
fn (GifPlayer) loop_count #
fn (p &GifPlayer) loop_count() int
loop_count returns the NETSCAPE loop count (0 = forever, >=1 finite).
fn (GifPlayer) delay_ms #
fn (p &GifPlayer) delay_ms(i int) int
delay_ms returns the display duration of frame i in milliseconds.
fn (GifPlayer) reset #
fn (mut p GifPlayer) reset()
reset clears the canvas to transparent and rewinds so the next step() renders frame 0. Used when a loop restarts.
fn (GifPlayer) step #
fn (mut p GifPlayer) step() ![]u8
step composites the next frame in sequence onto the persistent canvas and returns the full-canvas RGBA. The returned slice is the live canvas; the caller must copy it (e.g. upload to a texture) before the next step(), which mutates it in place.
fn (GifPlayer) free #
fn (mut p GifPlayer) free()
free releases the player's persistent canvas and the decoder's scratch. The viewer must call this when it drops a player to avoid leaking the long-lived canvas and arena.