Compare commits
4 commits
e469c84d1b
...
c128960451
Author | SHA1 | Date | |
---|---|---|---|
c128960451 | |||
f9aa226d9e | |||
510b4d9336 | |||
4a49b39159 |
4 changed files with 36 additions and 22 deletions
|
@ -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`
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
load :0;
|
load :0;
|
||||||
rotate 30;
|
rotate 30 #ff00ff;
|
||||||
quicksave;
|
quicksave;
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue