Repository navigation
Description
Unit
The rest of libnsgif, libobs/graphics/libnsgif/gif.c.h, into rust/obs-graphics as obs_graphics::gif: the GIF state machine and the public nsgif_* API of nsgif.h. Slice 2c, the last one of libnsgif, after #2466 (LZW decoder), #2488 (block parsers) and #2501 (frame decode and disposal). With it, the hybrid libobs has no C left from libnsgif.
nsgif_create,nsgif_destroy,nsgif_set_frame_delay_behaviour, the bitmap format to colour layout map;nsgif_data_scan(the header and screen descriptor through rust: Port the libnsgif GIF block parsers (graphics/libnsgif/gif.c.h) to obs-graphics (libnsgif slice 2a) #2488, the global colour table, the frame scan withnsgif__process_frame,nsgif__get_frame,nsgif__parse_image_dataand the wrappers of rust: Port the libnsgif GIF block parsers (graphics/libnsgif/gif.c.h) to obs-graphics (libnsgif slice 2a) #2488) andnsgif_data_complete;nsgif_frame_prepare(nsgif__next_displayable_frame,nsgif__frame_next,nsgif__redraw_rect_extend, the loop count, the delay rules),nsgif_reset;nsgif_frame_decode(nsgif__update_bitmap: the bitmap callbacks, the disposal of the previous frame through rust: Port the libnsgif frame decode and disposal (graphics/libnsgif/gif.c.h) to obs-graphics (libnsgif slice 2b) #2501,nsgif__record_frameand the saved frame);nsgif_get_info,nsgif_get_frame_info,nsgif_global_palette,nsgif_local_palette,nsgif_strerror,nsgif_str_disposal.
About 945 lines of code (with comments 1453).
Why
GIFs come from outside OBS (image sources, slideshows, GIF stinger and transition files). This part holds the frame table, the positions into the data across incremental scans, and the frame order and loop count that decide which frame is decoded next. After 2a and 2b the parsers and the pixel writes are Rust; the state that indexes into them is the last C.
Phase and position
A library unit like #2466, #2488 and #2501. Crate obs-graphics. gs_image_file is the only user of the API: the C libobs/graphics/image-file.c.h, and the Rust port of it (#1907, obs_graphics::image_file), which calls nsgif_* through extern "C". Both keep calling the C ABI in this slice; moving the Rust image_file onto the safe core directly can be a follow-up.
Seam
None needed: nsgif.h is the boundary, and nsgif_t is opaque to its callers. struct nsgif becomes a Rust struct behind the pointer.
nsgif_get_infoandnsgif_get_frame_inforeturn pointers into the state (nsgif_info_t,nsgif_frame_info_t), so those are#[repr(C)]in the Rust state, and a frame info pointer stays valid until the next scan, as with the C'srealloc.- The bitmap callbacks (
nsgif_bitmap_cb_vt: create, destroy, get_buffer, set_opaque, test_opaque, modified, get_rowspan; each may be NULL except the ones the C asserts) become a trait in the safe core; the shim adapts the C function pointers. - The C oracle's libnsgif (
obs_c_oracle_nsgif, used by the cargoimage_filetests) stops buildinggif.c.hin the hybrid, sonsgif_*resolves to the Rust shims there too, as for the LZW decoder.
Existing tests
test_nsgif_decode(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, rust: Port the libnsgif LZW decoder (graphics/libnsgif/lzw.c.h) to obs-graphics (libnsgif slice 1) #2466, rust: Port the libnsgif GIF block parsers (graphics/libnsgif/gif.c.h) to obs-graphics (libnsgif slice 2a) #2488, rust: Port the libnsgif frame decode and disposal (graphics/libnsgif/gif.c.h) to obs-graphics (libnsgif slice 2b) #2501): GIF files through the API, plus the cases of the earlier slices.test_image_file,test_image_file_version,test_image_file_version_filetime,test_media_gif_last_frameand the cargoimage_filetests decode GIFs throughgs_image_file: the Tier 2 for this slice.- The old-against-new differential of rust: Port the libnsgif GIF block parsers (graphics/libnsgif/gif.c.h) to obs-graphics (libnsgif slice 2a) #2488 and rust: Port the libnsgif frame decode and disposal (graphics/libnsgif/gif.c.h) to obs-graphics (libnsgif slice 2b) #2501 (40 000 generated and mutated GIFs, scanned whole, in steps and with
nsgif_data_complete, every frame prepared and decoded, two row spans) is the model for Tier 3 here. - New cases through
nsgif.h: incremental scans that stop inside every block kind; frames without image data and a trailer; the screen size quirk with the first frame growing the image; frame order, loops and the infinite last delay forloop_max0, 1 and N; non-displayable frames;nsgif_data_completemaking a partial frame displayable; disposal across frames (restore background, restore previous, the saved frame); a row span wider than the image; everynsgif_strerrorandnsgif_str_disposalvalue; NULL optional callbacks.
Plan
One PR:
- Characterization: the cases above against the C, through
nsgif.h, intest_nsgif_decode. - RED: the safe core in
obs-graphicswithtodo!(), Tier 1 tests (the cmocka cases 1:1, plus properties: no panic on any data and any call order, the frame count never shrinks, pointers fromnsgif_get_infostay valid). - GREEN: the core, a thin
#[no_mangle]shim fornsgif.h, the grouplibobs.nsgifremoved from the hybrid (moved to a ported group), Tier 3 against the unmodified C inrust/obs-c-oracle/(every result, every info and frame info field, the palettes and every decoded bitmap, for the generated GIFs in whole, incremental and complete scans), andport_comparisonnumbers for the scan and the full decode of an animated GIF. - Tier 2: the GIF tests above with Rust off and on.
If the PR turns out too large to review, it can split into the scan and info half and the prepare and decode half; both need struct nsgif in Rust, so the split would be by commits in one PR rather than two seams.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
vpacher commentedon Oct 26, 2026
Claiming: #2510
Plan as in the description: one PR (characterization, RED, GREEN with Tier 3 against the C oracle and
port_comparison, Tier 2). It starts on top of #2503 (#2501) and is rebased onto master after that merges.obs-build: Drop the Windows warning options of the ported libnsgif group
test: Characterize the libnsgif state machine and public API through …
obs-graphics: RED for the libnsgif state machine and public API (todo!)
obs-graphics: Port the libnsgif state machine and public API (#2510)
obs-build: Drop the Windows warning options of the ported libnsgif group
test: Characterize the libnsgif state machine and public API through …
obs-graphics: RED for the libnsgif state machine and public API (todo!)
obs-graphics: Port the libnsgif state machine and public API (#2510)
obs-build: Drop the Windows warning options of the ported libnsgif group
test: Characterize the libnsgif state machine and public API through …
obs-graphics: RED for the libnsgif state machine and public API (todo!)
obs-graphics: Port the libnsgif state machine and public API (#2510)
obs-build: Drop the Windows warning options of the ported libnsgif group
test: Characterize the libnsgif state machine and public API through …
obs-graphics: RED for the libnsgif state machine and public API (todo!)
obs-graphics: Port the libnsgif state machine and public API (#2510)
obs-build: Drop the Windows warning options of the ported libnsgif group
obs-graphics: Bound the gif_parity bitmaps; exclude a C read past the…
test: Scans of a GIF in parts end in the state of a whole scan (RED, #…
obs-graphics: Port the libnsgif state machine and public API (obs-rus…
libnsgif: Resume a scan at the frame's start after the end of the data (