add proper arguments to rotate cmd

This commit is contained in:
Luna 2019-07-22 22:22:01 -03:00
parent 510b4d9336
commit f9aa226d9e
3 changed files with 20 additions and 9 deletions

View File

@ -1,3 +1,3 @@
load :0;
rotate 30;
rotate 30 #ff00ff;
quicksave;

View File

@ -54,8 +54,6 @@ fn magickSave(image: *Image, wand: *mc.MagickWand) !void {
std.debug.warn("\tmagick: saving to '{}'..", c_tmpnam);
_ = mc.MagickDisplayImage(wand, c":0");
if (mc.MagickWriteImage(wand, c_tmpnam.ptr) != 1)
return error.MagickWriteFail;
@ -63,17 +61,19 @@ fn magickSave(image: *Image, wand: *mc.MagickWand) !void {
std.debug.warn("OK\n");
}
pub fn runRotate(image: *Image) !void {
/// Rotate the given image.
/// bgfill must point to a null-terminated string.
pub fn runRotate(image: *Image, deg: f32, bgfill: []const u8) !void {
var mctx = try magickLoad(image);
defer mctx.deinit();
var bg = mc.NewPixelWand();
defer mc.DestroyPixelWand(bg);
if (mc.PixelSetColor(bg, c"#000000") != 1)
if (mc.PixelSetColor(bg, bgfill.ptr) != 1)
return error.PixelSetColorFail;
if (mc.MagickRotateImage(mctx.wand, bg, f64(30)) != 1)
if (mc.MagickRotateImage(mctx.wand, bg, deg) != 1)
return error.RotateFail;
try magickSave(image, mctx.wand);

View File

@ -258,9 +258,16 @@ pub const Runner = struct {
try image.runCustomPlugin(custom.WildNoise, pos, map);
}
fn rotateCmd(self: *Runner) !void {
fn rotateCmd(
self: *Runner,
deg: f32,
bgfill: []const u8,
) !void {
var image = try self.getImage();
try magick.runRotate(image);
var c_bgfill = try std.cstr.addNullByte(self.allocator, bgfill);
defer self.allocator.free(c_bgfill);
try magick.runRotate(image, deg, c_bgfill);
}
fn runCommand(self: *Runner, cmd: *lang.Command) !void {
@ -424,7 +431,11 @@ pub const Runner = struct {
try self.wildNoiseCmd(pos, &map);
},
.Rotate => try self.rotateCmd(),
.Rotate => blk: {
const deg = try cmd.floatArgAt(0);
const bgfill = try cmd.argAt(1);
try self.rotateCmd(deg, bgfill);
},
else => blk: {
std.debug.warn("Unsupported command: {}\n", cmd.command);