Compare commits
2 commits
b056a0edb3
...
8784f3baf9
Author | SHA1 | Date | |
---|---|---|---|
8784f3baf9 | |||
73794e1867 |
3 changed files with 71 additions and 3 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;
|
||||
}
|
||||
|
||||
fn temporaryName(allocator: *std.mem.Allocator) ![]u8 {
|
||||
pub 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,6 +146,8 @@ 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) {
|
||||
|
|
|
@ -4,6 +4,69 @@ const images = @import("image.zig");
|
|||
|
||||
const Image = images.Image;
|
||||
|
||||
pub fn runRotate(image: *Image) !void {
|
||||
return error.NotImplementedYet;
|
||||
const mc = @cImport({
|
||||
@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;
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
|
||||
if (mc.MagickReadImage(mctx.wand, curpath.ptr) == .MagickFalse)
|
||||
return error.MagickReadFail;
|
||||
|
||||
return mctx;
|
||||
}
|
||||
|
||||
fn magickSave(image: *Image, mctx: *MagickContext) !void {
|
||||
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);
|
||||
|
||||
std.debug.warn(
|
||||
"\tmagick: saving from '{}' to '{}'\n",
|
||||
image.curpath,
|
||||
c_tmpnam,
|
||||
);
|
||||
|
||||
if (mc.MagickWriteImages(mctx.wand, c_tmpnam.ptr, .MagickTrue) == .MagickFalse)
|
||||
return error.MagickWriteFail;
|
||||
}
|
||||
|
||||
pub fn runRotate(image: *Image) !void {
|
||||
var mctx = try magickLoad(image);
|
||||
defer mctx.deinit();
|
||||
|
||||
// TODO run rotate here
|
||||
|
||||
try magickSave(image, &mctx);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue