Skip to content

Commit

Permalink
add vsh.printf to example
Browse files Browse the repository at this point in the history
  • Loading branch information
dnjulek committed Apr 25, 2024
1 parent 91c4f52 commit 116d94b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
4 changes: 2 additions & 2 deletions examples/example/build.zig.zon
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
.paths = .{""},
.dependencies = .{
.vapoursynth = .{
.url = "https://github.com/dnjulek/vapoursynth-zig/archive/2f6a59a6cccf23cec7ca8a3abb3f316593c5ed7b.tar.gz",
.hash = "12201cb4befda1224caa03a57a2188d5d5e985a7fdd7a8b3277d385dba4cb0e272cb",
.url = "https://github.com/dnjulek/vapoursynth-zig/archive/91c4f5249ac84416d654c1c5dc8b4b8dd90a7c2b.tar.gz",
.hash = "12205228fdfbb0f040c7f28e846fb82e14e27b4c9f0408203190ba38fbb0a4de8836",
},
},
}
18 changes: 16 additions & 2 deletions examples/example/src/invert_example.zig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const allocator = std.heap.c_allocator;
const InvertData = struct {
node: ?*vs.Node,
enabled: bool,
string_bufs: [2]?[]u8,
};

export fn invertGetFrame(n: c_int, activation_reason: vs.ActivationReason, instance_data: ?*anyopaque, frame_data: ?*?*anyopaque, frame_ctx: ?*vs.FrameContext, core: ?*vs.Core, vsapi: ?*const vs.API) callconv(.C) ?*const vs.Frame {
Expand Down Expand Up @@ -63,6 +64,9 @@ export fn invertFree(instance_data: ?*anyopaque, core: ?*vs.Core, vsapi: ?*const
_ = core;
const d: *InvertData = @ptrCast(@alignCast(instance_data));
vsapi.?.freeNode.?(d.node);
for (d.string_bufs) |buf| {
if (buf) |b| allocator.free(b);
}
allocator.destroy(d);
}

Expand All @@ -75,7 +79,12 @@ export fn invertCreate(in: ?*const vs.Map, out: ?*vs.Map, user_data: ?*anyopaque
const vi: *const vs.VideoInfo = vsapi.?.getVideoInfo.?(d.node);

if (!vsh.isConstantVideoFormat(vi) or (vi.format.sampleType != .Integer) or (vi.format.bitsPerSample != @as(c_int, 8))) {
vsapi.?.mapSetError.?(out, "Invert: only constant format 8bit integer input supported");
vsapi.?.mapSetError.?(out, vsh.printf(
allocator,
&d.string_bufs[0],
"Invert: only constant format 8bit integer input supported. Input clip is {}x{} {}-bits",
.{ vi.width, vi.height, vi.format.bitsPerSample },
).ptr);
vsapi.?.freeNode.?(d.node);
return;
}
Expand All @@ -84,7 +93,12 @@ export fn invertCreate(in: ?*const vs.Map, out: ?*vs.Map, user_data: ?*anyopaque
const enabled = vsh.mapGetN(i32, in, "enabled", 0, vsapi) orelse 1;

if ((enabled < 0) or (enabled > 1)) {
vsapi.?.mapSetError.?(out, "Invert: enabled must be 0 or 1");
vsapi.?.mapSetError.?(out, vsh.printf(
allocator,
&d.string_bufs[1],
"Invert: enabled must be 0 or 1. Passed: {}",
.{enabled},
).ptr);
vsapi.?.freeNode.?(d.node);
return;
}
Expand Down

0 comments on commit 116d94b

Please sign in to comment.