Compare commits
No commits in common. "8784f3baf994793067ae6151cd42c983a3f86f6a" and "b056a0edb305459b6cc8876fa599129f40e79e89" have entirely different histories.
8784f3baf9
...
b056a0edb3
3 changed files with 2 additions and 70 deletions
|
@ -1,3 +0,0 @@
|
|||
load :0;
|
||||
rotate 30;
|
||||
quicksave;
|
|
@ -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) {
|
||||
|
|
|
@ -4,69 +4,6 @@ const images = @import("image.zig");
|
|||
|
||||
const Image = images.Image;
|
||||
|
||||
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);
|
||||
return error.NotImplementedYet;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue