Skip to content

Images

sdk.images loads pictures and draws them in your windows. Wraith holds them on the GPU for you, in the overlay and anywhere else they get drawn. JS and Lua plugins get them too.

Decoding is slow, so load in a task. load reads and decodes the file on a worker, then comes back to the render thread.

fn loadLogo(self: *Plugin, io: std.Io) !void {
self.logo = try sdk.images.Image.load(io, self.ctx.allocator, self.logo_path);
}
// in start
try ctx.spawn(loadLogo, .{ self, ctx.io });

It reads PNG, JPEG, BMP, TGA and the first frame of a GIF. Sides over 16384 pixels get refused. Already have the bytes? Use Image.decode(bytes). Raw RGBA pixels go to Image.create(width, height, rgba).

pub fn draw(self: *MyWindow) void {
const logo = self.plugin.logo orelse return;
logo.draw(.{}); // its own size
logo.draw(.{ .fit = .width }); // as wide as the window, same shape
logo.draw(.{ .size = .{ 64, 64 }, .fit = .contain }); // inside 64 by 64
}

.tint multiplies its colors. For anything else, logo.texture() gives an ImTextureRef for ImGui calls like ImGui_ImageButton or ImDrawList_AddImage. It’s only good for that frame.

logo.deinit() from any thread. It leaves the GPU over the next frame or two. Calling it twice is fine, and whatever you didn’t free goes when your plugin does.

The CPU side works without the runtime. There’s decodePixels, encodePng, and fromCapture, which turns a frame from sdk.frame.capture into SDR pixels, tone-mapping HDR with an exposure in stops. linearFromCapture stops before that, with linear light you can write out as HDR. The screenshot plugin uses these for its PNGs and EXRs, so it’s a good example. All of it’s slow, so keep it on a worker.

Made with ♥ by Asgard