Compare commits
No commits in common. "c128960451ef24511d55f5332ed5fa7afc01e1e6" and "e469c84d1beafdda3c11d2584e152f55d4aec7dc" have entirely different histories.
c128960451
...
e469c84d1b
4 changed files with 22 additions and 36 deletions
|
@ -159,11 +159,9 @@ Parameters:
|
|||
- `repeat_bytes`, Amount of bytes to preload with random data and repeat
|
||||
throughout the image slice
|
||||
|
||||
## `rotate deg bgfill`
|
||||
## TODO `echo split index delay`
|
||||
|
||||
Rotate the image by `deg` degrees, filling the resulting triangles with `bgfill`.
|
||||
|
||||
`bgfill` is a hex string, e.g `#000000`.
|
||||
Run an echo filter on the given loaded file.
|
||||
|
||||
## `quicksave`
|
||||
|
||||
|
|
|
@ -1,3 +1,3 @@
|
|||
load :0;
|
||||
rotate 30 #ff00ff;
|
||||
rotate 30;
|
||||
quicksave;
|
||||
|
|
|
@ -45,36 +45,35 @@ fn magickLoad(image: *Image) !MagickContext {
|
|||
return mctx;
|
||||
}
|
||||
|
||||
fn magickSave(image: *Image, wand: *mc.MagickWand) !void {
|
||||
const allocator = image.allocator;
|
||||
fn magickSave(image: *Image, mctx: *MagickContext) !void {
|
||||
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(allocator, tmpnam);
|
||||
defer allocator.free(c_tmpnam);
|
||||
var c_tmpnam = try std.cstr.addNullByte(image.allocator, tmpnam);
|
||||
defer image.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;
|
||||
|
||||
image.curpath = tmpnam;
|
||||
std.debug.warn("OK\n");
|
||||
}
|
||||
|
||||
/// Rotate the given image.
|
||||
/// bgfill must point to a null-terminated string.
|
||||
pub fn runRotate(image: *Image, deg: f32, bgfill: []const u8) !void {
|
||||
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, bgfill.ptr) != 1)
|
||||
if (mc.PixelSetColor(bg, c"#ffffff") != 1)
|
||||
return error.PixelSetColorFail;
|
||||
|
||||
if (mc.MagickRotateImage(mctx.wand, bg, deg) != 1)
|
||||
if (mc.MagickRotateImage(mctx.wand, bg, 30) != 1)
|
||||
return error.RotateFail;
|
||||
|
||||
try magickSave(image, mctx.wand);
|
||||
try magickSave(image, &mctx);
|
||||
}
|
||||
|
|
|
@ -258,16 +258,9 @@ pub const Runner = struct {
|
|||
try image.runCustomPlugin(custom.WildNoise, pos, map);
|
||||
}
|
||||
|
||||
fn rotateCmd(
|
||||
self: *Runner,
|
||||
deg: f32,
|
||||
bgfill: []const u8,
|
||||
) !void {
|
||||
fn rotateCmd(self: *Runner) !void {
|
||||
var image = try self.getImage();
|
||||
var c_bgfill = try std.cstr.addNullByte(self.allocator, bgfill);
|
||||
defer self.allocator.free(c_bgfill);
|
||||
|
||||
try magick.runRotate(image, deg, c_bgfill);
|
||||
try magick.runRotate(image);
|
||||
}
|
||||
|
||||
fn runCommand(self: *Runner, cmd: *lang.Command) !void {
|
||||
|
@ -431,11 +424,7 @@ pub const Runner = struct {
|
|||
try self.wildNoiseCmd(pos, &map);
|
||||
},
|
||||
|
||||
.Rotate => blk: {
|
||||
const deg = try cmd.floatArgAt(0);
|
||||
const bgfill = try cmd.argAt(1);
|
||||
try self.rotateCmd(deg, bgfill);
|
||||
},
|
||||
.Rotate => try self.rotateCmd(),
|
||||
|
||||
else => blk: {
|
||||
std.debug.warn("Unsupported command: {}\n", cmd.command);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue