Compare commits

..

4 commits

Author SHA1 Message Date
c128960451 add rotate command to docs 2019-07-22 22:27:00 -03:00
f9aa226d9e add proper arguments to rotate cmd 2019-07-22 22:22:01 -03:00
510b4d9336 rm a.bmp 2019-07-22 22:16:42 -03:00
4a49b39159 make magickSave edit Image.curpath 2019-07-22 22:15:06 -03:00
4 changed files with 36 additions and 22 deletions

View file

@ -159,9 +159,11 @@ Parameters:
- `repeat_bytes`, Amount of bytes to preload with random data and repeat - `repeat_bytes`, Amount of bytes to preload with random data and repeat
throughout the image slice throughout the image slice
## TODO `echo split index delay` ## `rotate deg bgfill`
Run an echo filter on the given loaded file. Rotate the image by `deg` degrees, filling the resulting triangles with `bgfill`.
`bgfill` is a hex string, e.g `#000000`.
## `quicksave` ## `quicksave`

View file

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

View file

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

View file

@ -258,9 +258,16 @@ pub const Runner = struct {
try image.runCustomPlugin(custom.WildNoise, pos, map); 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(); 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 { fn runCommand(self: *Runner, cmd: *lang.Command) !void {
@ -424,7 +431,11 @@ pub const Runner = struct {
try self.wildNoiseCmd(pos, &map); 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: { else => blk: {
std.debug.warn("Unsupported command: {}\n", cmd.command); std.debug.warn("Unsupported command: {}\n", cmd.command);