Backlog/lib/spng
peterino2 b0d1a81d84 split between zig and c libraries complete 2025-11-09 23:30:44 -08:00
..
spng Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
src updated spng, theoratest, spng, tracy 2025-10-13 21:22:18 -07:00
.gitignore Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
.gitmodules Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
README.md Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
build.zig split between zig and c libraries complete 2025-11-09 23:30:44 -08:00
build.zig.zon fixed all tests and added bh.zig 2025-11-06 20:42:48 -08:00
miniz.c Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
miniz.h Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00
test.zig saving 2025-11-02 00:55:21 -07:00
testpng.png Backlog initial-comit SDL gpu examples cooking shaders properly 2025-04-07 19:51:46 -07:00

README.md

zig-spng: fast multithreaded png decoding/encoding

zig bindings to the spng library, a more threadsafe solution for pngs than stb I didn't find one published anywhere so here it is.

Usage:

Link to your exe with build.zig by calling linkSpng.

const spngBuild = @import("zig-spng/build.zig");

...

spngBuild.linkSpng(b, myExe);

Decoding a file


    var decodeBuffer = try allocator.alloc(u8, 500 * 1000 * 1000); // something arbitrarily large
    defer allocator.free(decodeBuffer);

    var decoder2 = try spng.SpngContext.newDecoder();
    defer decoder2.deinit();
    try decoder2.setFile("testpng.png");

    var len = try decoder2.decode(decodeBuffer, spng.SPNG_FMT_RGBA8, spng.SPNG_DECODE_TRNS);
    var header = try decoder2.getHeader();

    std.debug.print("decoded size = {d}\nheader={any}", .{ len, header });

output:

decoded size = 528540
header=.home.sear.git.zig-cache.o.6c6df69e4cfcdfdde0e33efd51510c3c.cimport.struct_spng_ihdr{ .width = 383, .height = 345, .bit_depth = 8, .color_type = 2, .compression_method = 0, .filter_method = 0, .interlace_method = 0 }