add magickwand load/unload
This commit is contained in:
parent
b056a0edb3
commit
73794e1867
3 changed files with 58 additions and 2 deletions
3
examples/rotate.scri
Normal file
3
examples/rotate.scri
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
load :0;
|
||||||
|
rotate 30;
|
||||||
|
quicksave;
|
|
@ -67,7 +67,7 @@ fn sf_tell(file: *c.SNDFILE) i64 {
|
||||||
return -frames;
|
return -frames;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
|
pub fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
|
||||||
const template_start = "/temp/temp_";
|
const template_start = "/temp/temp_";
|
||||||
const template = "/tmp/temp_XXXXXXXX";
|
const template = "/tmp/temp_XXXXXXXX";
|
||||||
var nam = try allocator.alloc(u8, template.len);
|
var nam = try allocator.alloc(u8, template.len);
|
||||||
|
@ -146,6 +146,8 @@ pub const Image = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn close(self: *Image) void {
|
pub fn close(self: *Image) void {
|
||||||
|
//self.allocator.free(self.path);
|
||||||
|
//self.allocator.free(self.curpath);
|
||||||
var st: i32 = c.sf_close(self.sndfile);
|
var st: i32 = c.sf_close(self.sndfile);
|
||||||
|
|
||||||
if (st != 0) {
|
if (st != 0) {
|
||||||
|
|
|
@ -4,6 +4,57 @@ const images = @import("image.zig");
|
||||||
|
|
||||||
const Image = images.Image;
|
const Image = images.Image;
|
||||||
|
|
||||||
pub fn runRotate(image: *Image) !void {
|
const mc = @cImport({
|
||||||
return error.NotImplementedYet;
|
@cInclude("MagickWand/MagickWand.h");
|
||||||
|
});
|
||||||
|
|
||||||
|
pub const MagickContext = struct {
|
||||||
|
wand: *mc.MagickWand,
|
||||||
|
|
||||||
|
pub fn init() !MagickContext {
|
||||||
|
mc.MagickWandGenesis();
|
||||||
|
|
||||||
|
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.MagickWandTerminus();
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn doErr(self: *MagickContext) !void {
|
||||||
|
return error.WandError;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn runRotate(image: *Image) !void {
|
||||||
|
mc.MagickWandGenesis();
|
||||||
|
|
||||||
|
var mctx = try MagickContext.init();
|
||||||
|
defer mctx.deinit();
|
||||||
|
errdefer mctx.deinit();
|
||||||
|
|
||||||
|
var status: mc.MagickBooleanType = undefined;
|
||||||
|
|
||||||
|
var curpath = try std.cstr.addNullByte(image.allocator, image.curpath);
|
||||||
|
defer image.allocator.free(curpath);
|
||||||
|
|
||||||
|
status = mc.MagickReadImage(mctx.wand, curpath.ptr);
|
||||||
|
if (status == .MagickFalse) try mctx.doErr();
|
||||||
|
|
||||||
|
// TODO run rotate here
|
||||||
|
|
||||||
|
var tmpnam = try images.temporaryName(image.allocator);
|
||||||
|
defer image.allocator.free(tmpnam);
|
||||||
|
|
||||||
|
var c_tmpnam = try std.cstr.addNullByte(image.allocator, tmpnam);
|
||||||
|
defer image.allocator.free(c_tmpnam);
|
||||||
|
|
||||||
|
status = mc.MagickWriteImages(mctx.wand, c_tmpnam.ptr, .MagickTrue);
|
||||||
|
if (status == .MagickFalse) try mctx.doErr();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue