magick: reopen the file instead of just setting curpath

This commit is contained in:
Luna 2019-07-22 22:48:37 -03:00
parent c128960451
commit c0b70a81b1
2 changed files with 13 additions and 6 deletions

View File

@ -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);
}
};

View File

@ -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");
}