make magickSave edit Image.curpath

This commit is contained in:
Luna 2019-07-22 22:15:06 -03:00
parent e469c84d1b
commit 4a49b39159

View file

@ -45,35 +45,36 @@ fn magickLoad(image: *Image) !MagickContext {
return mctx;
}
fn magickSave(image: *Image, mctx: *MagickContext) !void {
var tmpnam = try images.temporaryName(image.allocator);
defer image.allocator.free(tmpnam);
fn magickSave(image: *Image, wand: *mc.MagickWand) !void {
const allocator = image.allocator;
var c_tmpnam = try std.cstr.addNullByte(image.allocator, tmpnam);
defer image.allocator.free(c_tmpnam);
var tmpnam = try images.temporaryName(allocator);
var c_tmpnam = try std.cstr.addNullByte(allocator, tmpnam);
defer allocator.free(c_tmpnam);
std.debug.warn(
"\tmagick: saving from '{}' to '{}'\n",
image.curpath,
c_tmpnam,
);
std.debug.warn("\tmagick: saving to '{}'..", c_tmpnam);
if (mc.MagickWriteImage(mctx.wand, c_tmpnam.ptr) != 1)
_ = mc.MagickDisplayImage(wand, c":0");
if (mc.MagickWriteImage(wand, c_tmpnam.ptr) != 1)
return error.MagickWriteFail;
image.curpath = tmpnam;
std.debug.warn("OK\n");
}
pub fn runRotate(image: *Image) !void {
var mctx = try magickLoad(image);
defer mctx.deinit();
var bg = mc.NewPixelWand().?;
var bg = mc.NewPixelWand();
defer mc.DestroyPixelWand(bg);
if (mc.PixelSetColor(bg, c"#ffffff") != 1)
if (mc.PixelSetColor(bg, c"#000000") != 1)
return error.PixelSetColorFail;
if (mc.MagickRotateImage(mctx.wand, bg, 30) != 1)
if (mc.MagickRotateImage(mctx.wand, bg, f64(30)) != 1)
return error.RotateFail;
try magickSave(image, &mctx);
try magickSave(image, mctx.wand);
}