Compare commits

..

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

9 changed files with 11 additions and 4245 deletions

View file

@ -13,7 +13,7 @@ glitch art "framework", ???????? language??? something?
- zig at https://ziglang.org
- libc, lilv and libsndfile
- an appreciation for glitched anime girls on your hard drive
- graphicsmagick for the `rotate` command
- optional: imagemagick to convert from whatever to bmp
## plugin depedencies:
- lv2 default plugins (most specifically the eg-amp plugin)
@ -37,3 +37,8 @@ scritcher examples/middle_amp.scri blah.bmp
// blah_g1.bmp, the second saves to blah_g2.bmp, etc.
$your_image_viewer blah_g1.bmp
```
## todo
- search other plugins
- conquer the world for glitchy anime girls

View file

@ -10,11 +10,7 @@ pub fn build(b: *Builder) void {
exe.linkSystemLibrary("sndfile");
exe.linkSystemLibrary("c");
exe.linkSystemLibrary("GraphicsMagickWand");
exe.linkSystemLibrary("GraphicsMagick");
exe.addIncludeDir("/usr/include/lilv-0");
exe.addIncludeDir("/usr/include/GraphicsMagick");
const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep());

View file

@ -114,7 +114,7 @@ Parameters:
- `gain`: Gain, 0..12, default 0
- `noClip`: Soft Clip (assumed boolean), 0..1, default 0
## `delay split index seed gain feedback_pc tap_count first_delay delay_range delay_scale delay_rand_pc gain_scale wet`
## `delay seed gain feedback_pc tap_count first_delay delay_range delay_scale delay_rand_pc gain_scale wet`
Parameters:
- `seed`: Random seed, 0..1000, default 0
@ -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`

View file

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

View file

@ -67,7 +67,7 @@ fn sf_tell(file: *c.SNDFILE) i64 {
return -frames;
}
pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
const template_start = "/temp/temp_";
const template = "/tmp/temp_XXXXXXXX";
var nam = try allocator.alloc(u8, template.len);
@ -146,8 +146,6 @@ pub const Image = struct {
}
pub fn close(self: *Image) void {
//self.allocator.free(self.path);
//self.allocator.free(self.curpath);
var st: i32 = c.sf_close(self.sndfile);
if (st != 0) {
@ -340,7 +338,7 @@ pub const Image = struct {
}
pub fn saveTo(self: *Image, out_path: []const u8) !void {
std.debug.warn("\timg: copy from '{}' to '{}'\n", self.curpath, out_path);
std.debug.warn("saved to '{}'\n", out_path);
try std.fs.copyFile(self.curpath, out_path);
}

View file

@ -28,8 +28,6 @@ pub const CommandType = enum {
RevDelay,
Noise,
WildNoise,
Rotate,
};
pub const Command = struct {
@ -161,9 +159,6 @@ pub const Lang = struct {
// custom implementations (not lv2)
_ = try self.keywords.put("noise", .Noise);
_ = try self.keywords.put("wildnoise", .WildNoise);
// even more custom
_ = try self.keywords.put("rotate", .Rotate);
}
pub fn parse(self: *Lang, data: []const u8) !CommandList {

View file

@ -1,80 +0,0 @@
// imagemagick plugins
const std = @import("std");
const images = @import("image.zig");
const Image = images.Image;
const mc = @import("magick_wand.zig");
pub const MagickContext = struct {
wand: *mc.MagickWand,
pub fn init() !MagickContext {
mc.InitializeMagick(null);
var wand = mc.NewMagickWand();
if (wand == null) return error.WandCreateFail;
return MagickContext{
.wand = wand.?,
};
}
pub fn deinit(self: *MagickContext) void {
_ = mc.DestroyMagickWand(self.wand);
mc.DestroyMagick();
}
pub fn doErr(self: *MagickContext) !void {
return error.WandError;
}
};
fn magickLoad(image: *Image) !MagickContext {
var mctx = try MagickContext.init();
errdefer mctx.deinit();
var curpath = try std.cstr.addNullByte(image.allocator, image.curpath);
defer image.allocator.free(curpath);
std.debug.warn("loading '{}'\n", curpath);
if (mc.MagickReadImage(mctx.wand, curpath.ptr) != 1)
return error.MagickReadFail;
return mctx;
}
fn magickSave(image: *Image, wand: *mc.MagickWand) !void {
const allocator = image.allocator;
var tmpnam = try images.temporaryName(allocator);
var c_tmpnam = try std.cstr.addNullByte(allocator, tmpnam);
defer allocator.free(c_tmpnam);
std.debug.warn("\tmagick: saving to '{}'..", c_tmpnam);
if (mc.MagickWriteImage(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 {
var mctx = try magickLoad(image);
defer mctx.deinit();
var bg = mc.NewPixelWand();
defer mc.DestroyPixelWand(bg);
if (mc.PixelSetColor(bg, bgfill.ptr) != 1)
return error.PixelSetColorFail;
if (mc.MagickRotateImage(mctx.wand, bg, deg) != 1)
return error.RotateFail;
try magickSave(image, mctx.wand);
}

File diff suppressed because it is too large Load diff

View file

@ -3,7 +3,6 @@ const lang = @import("lang.zig");
const images = @import("image.zig");
const plugin = @import("plugin.zig");
const custom = @import("custom.zig");
const magick = @import("magick.zig");
const Position = plugin.Position;
const ParamList = plugin.ParamList;
@ -258,18 +257,6 @@ pub const Runner = struct {
try image.runCustomPlugin(custom.WildNoise, pos, map);
}
fn rotateCmd(
self: *Runner,
deg: f32,
bgfill: []const u8,
) !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);
}
fn runCommand(self: *Runner, cmd: *lang.Command) !void {
var params = ParamList.init(self.allocator);
defer params.deinit();
@ -431,12 +418,6 @@ 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);
},
else => blk: {
std.debug.warn("Unsupported command: {}\n", cmd.command);
break :blk RunError.UnknownCommand;