Compare commits

..

No commits in common. "c128960451ef24511d55f5332ed5fa7afc01e1e6" and "e469c84d1beafdda3c11d2584e152f55d4aec7dc" have entirely different histories.

4 changed files with 22 additions and 36 deletions

View file

@ -159,11 +159,9 @@ 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
## `rotate deg bgfill` ## TODO `echo split index delay`
Rotate the image by `deg` degrees, filling the resulting triangles with `bgfill`. Run an echo filter on the given loaded file.
`bgfill` is a hex string, e.g `#000000`.
## `quicksave` ## `quicksave`

View file

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

View file

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

View file

@ -258,16 +258,9 @@ pub const Runner = struct {
try image.runCustomPlugin(custom.WildNoise, pos, map); try image.runCustomPlugin(custom.WildNoise, pos, map);
} }
fn rotateCmd( fn rotateCmd(self: *Runner) !void {
self: *Runner,
deg: f32,
bgfill: []const u8,
) !void {
var image = try self.getImage(); var image = try self.getImage();
var c_bgfill = try std.cstr.addNullByte(self.allocator, bgfill); try magick.runRotate(image);
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 {
@ -431,11 +424,7 @@ pub const Runner = struct {
try self.wildNoiseCmd(pos, &map); try self.wildNoiseCmd(pos, &map);
}, },
.Rotate => blk: { .Rotate => try self.rotateCmd(),
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);