Something went wrong. Try again.
Zig bindings to Google's WUFFS image decoders for PNG, JPEG, GIF and Netpbm
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465// SPDX-FileCopyrightText: © 2026 Jeffrey C. Ollie <jeff@ocjtech.us>// SPDX-License-Identifier: MIT
//! A program that exists only so that `zig build check` can prove this//! library still builds for a target that has no libc at all.//!//! It has to be an executable and not a library, because the thing that goes//! wrong without libc goes wrong at link time rather than compile time: the//! `wuffs_*__decoder__alloc` constructors WUFFS generates call calloc and//! free, and nothing here calls one of them, so a static library is happy to//! leave the references dangling and only a link says whether they were//! discarded. It also has to name the decoders, since Zig analyses nothing it//! is not asked for and an empty program compiles for anything.
const std = @import("std");const wuffs = @import("wuffs");
// Freestanding has no stderr, so std's default log implementation does not// compile there. Every freestanding program has to say what logging means;// this one says it means nothing.pub const std_options: std.Options = .{ .logFn = logNowhere };
fn logNowhere( comptime _: std.log.Level, comptime _: @TypeOf(.enum_literal), comptime _: []const u8, _: anytype,) void {}
// No libc means no malloc, so a fixed buffer is the whole heap.var heap: [1 << 20]u8 = undefined;var input: [4096]u8 = undefined;
export fn input_ptr() [*]u8 { return &input;}
fn widthOf(comptime decode: anytype, len: usize) u32 { var fba: std.heap.FixedBufferAllocator = .init(&heap); const image = decode(fba.allocator(), input[0..len]) catch return 0; return image.width;}
export fn png_width(len: usize) u32 { return widthOf(wuffs.png.decode, len);}
export fn jpeg_width(len: usize) u32 { return widthOf(wuffs.jpeg.decode, len);}
export fn gif_width(len: usize) u32 { return widthOf(wuffs.gif.decode, len);}
export fn netpbm_width(len: usize) u32 { return widthOf(wuffs.netpbm.decode, len);}
export fn rgb_to_rgba(len: usize) usize { var fba: std.heap.FixedBufferAllocator = .init(&heap); const out = wuffs.swizzle.rgbToRgba(fba.allocator(), input[0..len]) catch return 0; return out.len;}