Skip to content

rust: Port graphics/image-file.c.h to obs-graphics #1907

Closed

Description

@zackees

Unit

libobs/graphics/image-file.c.h, all of it, into rust/obs-graphics. About 400 lines. Unit 6 of #1846. It loads an image file for a texture (gs_image_file_ex_*): animated GIFs through the vendored libnsgif, everything else through gs_create_texture_file_data3 (graphics-ffmpeg), and steps GIF animation by elapsed time.

  • gs_image_file_ex_init
  • gs_image_file_ex_free
  • gs_image_file_ex_init_texture
  • gs_image_file_ex_tick
  • gs_image_file_ex_update_texture

Phase and position

Phase 6 (#444), next to texture-render (#1860). The file is its own include in the libobs.media unity group, so the whole file can leave the production build by moving to the ported graphics group. No open port touches it.

Dependencies and existing tests

struct gs_image_file_ex in the public graphics/image-file.h is ABI: the Rust shim uses a #[repr(C)] mirror and layout tests check it against the C. struct gs_image_file_internal is private to the file; the Rust side keeps its own private block, allocated with bzalloc so bnum_allocs counts the same.

What stays C and is called through extern declarations: libnsgif (nsgif_*, vendored), gs_create_texture_file_data3 (graphics-ffmpeg), gs_texture_create, gs_texture_destroy, gs_texture_set_image (graphics.c). The inline helpers it uses (gs_premultiply_xyza_loop, gs_premultiply_xyza_srgb_loop, gs_get_format_bpp) are ported with it. Cargo tests link libnsgif and a recording stand-in for the gs_* calls from the oracle crate, as #1861 did.

No test covers the file today beyond test_image_size_precheck (needs a display). The characterization needs no GPU: GIF and PNG fixtures, the same hand-built graphics_t with a fake device as test_texture_render, and it runs against the C build, the C reference and hybrid libobs.

Plan

One PR, as #1846 asks:

  1. Characterization: test/cmocka/test_image_file.c with small GIF/PNG fixtures: cx/cy/format/loaded/is_animated_gif, missing files, oversized GIF, single-frame GIF falling back to FFmpeg, alpha modes, tick timing across frames and loop counts, texture create/update/destroy calls, bnum_allocs.
  2. RED: Tier 1 in the existing obs-tests-graphics binary against a todo!() safe core.
  3. GREEN: safe core for the timing math, decode range, premultiply; #[no_mangle] shim for the five exports. image-file.c.h moves to libobs.ported-graphics+.h.c; Windows exports in rust-exports.d/obs-graphics-image_file.txt. No public header or exported symbol change.
  4. Tier 3: the original built as oracle_gs_image_file_ex_*; proptest over tick sequences comparing every public field, the frame bytes passed to the device and the call log; layout tests; one mutation check.
  5. rust/README.md row and port_comparison bench.

Tier 4 does not apply.

Activity

  1. zackees commented on Oct 23, 2026

    @zackees
    MemberAuthor

    Claiming: #1907 (unit 6 of #1846).

    1. Characterization cmocka test with GIF/PNG fixtures.
    2. RED: Tier 1 against todo!() stubs, draft PR.
    3. GREEN port into obs-graphics, file moves to the ported graphics group.
    4. Tier 3 oracle parity (proptest over ticks, layout, mutation check).
    5. README row and bench.

    First PR today.

  2. added
    claimed
    on Oct 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    claimed

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions