image/codecs/gif

GIF codec — references/image/src/codecs/gif.rs (684) + gif@0.14.1 Header, LSD, GCT/LCT, GCE (disposal/delay/transparent), Netscape loop, image descriptors, interlace, LZW sub-blocks, trailer. Pure Nim.

Types

GifDisposal = enum
  gdNone = 0, gdKeep = 1, gdBackground = 2, gdPrevious = 3
GifFrame = object
  left*, top*, width*, height*: uint16
  interlaced*: bool
  delay*: Delay
  disposal*: GifDisposal
  transparent*: tuple[has: bool, index: uint8]
  palette*: seq[tuple[r, g, b: uint8]]
  indices*: seq[uint8]
GifImage = object
  width*, height*: uint16
  globalPalette*: seq[tuple[r, g, b: uint8]]
  bgIndex*: uint8
  loopCount*: LoopCount
  frames*: seq[GifFrame]

Procs

proc decodeGif(data: seq[uint8]): ImageResult[GifImage] {....raises: [], tags: [],
    forbids: [].}
proc encodeGif(frames: seq[seq[uint8]]; width, height: uint16;
               palette: seq[tuple[r, g, b: uint8]]; delaysCs: seq[uint16] = @[]): seq[
    uint8] {....raises: [KeyError], tags: [], forbids: [].}
Minimal GIF89a encoder: GCT 256 entries (pow2), one frame per indices seq.
proc gifFirstToRgba(data: seq[uint8]): ImageResult[RgbaImage] {....raises: [],
    tags: [], forbids: [].}
proc gifFrameToRgba(img: GifImage; fi: int): ImageResult[RgbaImage] {.
    ...raises: [], tags: [], forbids: [].}
Composite frame fi over canvas using GCT/LCT + transparency + disposal none. Full disposal compositing across frames is left to the caller; this renders the frame's own rectangle.