Repository navigation
Description
Unit
The LZW decoder of libnsgif, libobs/graphics/libnsgif/lzw.c.h (611 lines), into rust/obs-graphics as obs_graphics::lzw. Slice 1 of libnsgif. After #2465, so the port starts from the fixed C.
lzw_context_create/lzw_context_destroy;lzw_decode_init(minimum code size, the GIF sub-block chain) andlzw_decode_init_map(the variant that writes pixels through a colour table, with the transparent index);lzw_decodeandlzw_decode_map: the code reader over sub-blocks (fast and slow path), the code table, clear and end-of-information codes, the output stack, and the results (LZW_OK,LZW_OK_EOD,LZW_NO_MEM,LZW_NO_DATA,LZW_EOI_CODE,LZW_NO_COLOUR,LZW_BAD_ICODE,LZW_BAD_PARAM,LZW_BAD_CODE).
gif.c.h stays C in this slice and calls the same lzw.h API.
Why libnsgif
GIFs come from outside OBS (image sources, slideshows, GIF stinger and transition files, files people share), and libnsgif is a third-party C decoder with dense index arithmetic. The LZW part is self-contained, needs no libobs seam and has a small C API, so a byte-exact differential test against the C is straightforward.
Phase and position
A library unit like #1907 (image-file), not Phase 6: no libobs core state and no seam. Crate obs-graphics (it exists). Next slices: gif.c.h (header, blocks, frame decode and disposal) behind the existing nsgif_* API, possibly in two parts (scan/info, frame decode). Not the gif crate from image-rs: it differs from libnsgif on damaged files, and the port keeps libnsgif's behaviour.
Seam
None: lzw.h is already the boundary. The Rust shim exports the same lzw_* functions; struct lzw_ctx becomes an opaque Rust context behind the pointer (gif.c.h only holds the pointer).
Existing tests
test_image_fileandtest_media_gif_last_framedecode GIFs through libobs: the Tier 2 for this slice.- bug: libnsgif: the last LZW code is lost when it ends on a byte boundary at the end of the data (upstream fix 2255b2f74) #2465 adds
lzweod.gif. - No test calls
lzw_*directly. New cases: the code sizes 2 to 8, codes that end on and across byte and sub-block boundaries, clear codes, a full code table (4096), the end-of-information code, data that ends early, a zero-length sub-block, invalid first codes and codes beyond the table.
Plan
One PR:
- Characterization: the cases above against the C (through
lzw.h), in the existing test binary for this category. - RED: the safe core in
obs-graphicswithtodo!(), Tier 1 tests (the cmocka cases 1:1, plus properties: no panic on any input, output length within the frame). - GREEN: the core, a thin
#[no_mangle]shim forlzw.h, the include moved to a ported group, Tier 3 against the unmodified C inrust/obs-c-oracle/(byte-exact output and results for proptest-generated code streams and for the GIFs in the tree), andport_comparisonnumbers for a large frame. - Tier 2: the GIF tests above with Rust off and on.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
vpacher commentedon Oct 26, 2026
Claiming: #2466
Plan as in the description: one PR (characterization, RED, GREEN with Tier 3 against the C oracle and
port_comparison, Tier 2). It starts after #2465, so the oracle is the fixed C.obs-graphics: Port the libnsgif LZW decoder (obs-rust#2466) (obs-rust…
obs-graphics: Speed up the LZW decoder's stack decode (obs-rust#2504) (…
obs-graphics: Port the libnsgif frame decode and disposal (obs-rust#2501