From c0b70a81b1a14c280c85e4bc9837bc4046bcae12 Mon Sep 17 00:00:00 2001 From: Luna Date: Mon, 22 Jul 2019 22:48:37 -0300 Subject: [PATCH] magick: reopen the file instead of just setting curpath --- src/image.zig | 17 ++++++++++++----- src/magick.zig | 2 +- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/image.zig b/src/image.zig index 1a4946f..1155501 100644 --- a/src/image.zig +++ b/src/image.zig @@ -221,6 +221,16 @@ pub const Image = struct { return seek_pos; } + pub fn reopen(self: *Image, path: []const u8) !void { + var in_fmt = mkSfInfo(); + + self.sndfile = try sopen(self.allocator, path, c.SFM_READ, &in_fmt); + self.curpath = path; + self.frames = @intCast(usize, in_fmt.frames); + + std.debug.warn("\timage: reopened on '{}'\n", self.curpath); + } + /// Run a plugin over the image. /// This setups a new lilv world/plugin among other things. /// The internal SNDFILE pointer is modified to point to the output of the @@ -334,9 +344,7 @@ pub const Image = struct { _ = c.sf_close(out_file); _ = c.sf_close(self.sndfile); - // reopen the file as SFM_READ so we can run plugin chains etc - self.sndfile = try sopen(self.allocator, tmpnam, c.SFM_READ, &out_fmt); - self.curpath = tmpnam; + try self.reopen(tmpnam); } pub fn saveTo(self: *Image, out_path: []const u8) !void { @@ -414,7 +422,6 @@ pub const Image = struct { _ = c.sf_close(self.sndfile); // reopen the file as SFM_READ so we can run plugin chains etc - self.sndfile = try sopen(self.allocator, tmpnam, c.SFM_READ, &out_fmt); - self.curpath = tmpnam; + try self.reopen(tmpnam); } }; diff --git a/src/magick.zig b/src/magick.zig index 7effc94..bd88986 100644 --- a/src/magick.zig +++ b/src/magick.zig @@ -57,7 +57,7 @@ fn magickSave(image: *Image, wand: *mc.MagickWand) !void { if (mc.MagickWriteImage(wand, c_tmpnam.ptr) != 1) return error.MagickWriteFail; - image.curpath = tmpnam; + try image.reopen(tmpnam); std.debug.warn("OK\n"); }