move to graphicsmagick

This commit is contained in:
Luna 2019-07-22 21:50:11 -03:00
parent 8784f3baf9
commit 6775773674
4 changed files with 4143 additions and 18 deletions

View file

@ -10,17 +10,11 @@ pub fn build(b: *Builder) void {
exe.linkSystemLibrary("sndfile"); exe.linkSystemLibrary("sndfile");
exe.linkSystemLibrary("c"); exe.linkSystemLibrary("c");
// magick libraries exe.linkSystemLibrary("GraphicsMagickWand");
exe.linkSystemLibrary("MagickWand-7.Q16HDRI"); exe.linkSystemLibrary("GraphicsMagick");
exe.linkSystemLibrary("MagickCore-7.Q16HDRI");
//exe.addArgs([_]u8{
// "-DMAGICKCORE_HDRI_ENABLE=1",
// "-DMAGICKCORE_QUANTUM_DEPTH=16",
//});
exe.addIncludeDir("/usr/include/lilv-0"); exe.addIncludeDir("/usr/include/lilv-0");
exe.addIncludeDir("/usr/include/ImageMagick-7"); exe.addIncludeDir("/usr/include/GraphicsMagick");
const run_cmd = exe.run(); const run_cmd = exe.run();
run_cmd.step.dependOn(b.getInstallStep()); run_cmd.step.dependOn(b.getInstallStep());

View file

@ -340,7 +340,7 @@ pub const Image = struct {
} }
pub fn saveTo(self: *Image, out_path: []const u8) !void { pub fn saveTo(self: *Image, out_path: []const u8) !void {
std.debug.warn("saved to '{}'\n", out_path); std.debug.warn("\timg: copy from '{}' to '{}'\n", self.curpath, out_path);
try std.fs.copyFile(self.curpath, out_path); try std.fs.copyFile(self.curpath, out_path);
} }

View file

@ -4,15 +4,13 @@ const images = @import("image.zig");
const Image = images.Image; const Image = images.Image;
const mc = @cImport({ const mc = @import("magick_wand.zig");
@cInclude("MagickWand/MagickWand.h");
});
pub const MagickContext = struct { pub const MagickContext = struct {
wand: *mc.MagickWand, wand: *mc.MagickWand,
pub fn init() !MagickContext { pub fn init() !MagickContext {
mc.MagickWandGenesis(); mc.InitializeMagick(null);
var wand = mc.NewMagickWand(); var wand = mc.NewMagickWand();
if (wand == null) return error.WandCreateFail; if (wand == null) return error.WandCreateFail;
@ -24,7 +22,7 @@ pub const MagickContext = struct {
pub fn deinit(self: *MagickContext) void { pub fn deinit(self: *MagickContext) void {
_ = mc.DestroyMagickWand(self.wand); _ = mc.DestroyMagickWand(self.wand);
mc.MagickWandTerminus(); mc.DestroyMagick();
} }
pub fn doErr(self: *MagickContext) !void { pub fn doErr(self: *MagickContext) !void {
@ -39,7 +37,9 @@ fn magickLoad(image: *Image) !MagickContext {
var curpath = try std.cstr.addNullByte(image.allocator, image.curpath); var curpath = try std.cstr.addNullByte(image.allocator, image.curpath);
defer image.allocator.free(curpath); defer image.allocator.free(curpath);
if (mc.MagickReadImage(mctx.wand, curpath.ptr) == .MagickFalse) std.debug.warn("loading '{}'\n", curpath);
if (mc.MagickReadImage(mctx.wand, curpath.ptr) != 1)
return error.MagickReadFail; return error.MagickReadFail;
return mctx; return mctx;
@ -58,7 +58,7 @@ fn magickSave(image: *Image, mctx: *MagickContext) !void {
c_tmpnam, c_tmpnam,
); );
if (mc.MagickWriteImages(mctx.wand, c_tmpnam.ptr, .MagickTrue) == .MagickFalse) if (mc.MagickWriteImage(mctx.wand, c_tmpnam.ptr) != 1)
return error.MagickWriteFail; return error.MagickWriteFail;
} }
@ -66,7 +66,14 @@ pub fn runRotate(image: *Image) !void {
var mctx = try magickLoad(image); var mctx = try magickLoad(image);
defer mctx.deinit(); defer mctx.deinit();
// TODO run rotate here var bg = mc.NewPixelWand().?;
defer mc.DestroyPixelWand(bg);
if (mc.PixelSetColor(bg, c"#ffffff") != 1)
return error.PixelSetColorFail;
if (mc.MagickRotateImage(mctx.wand, bg, 30) != 1)
return error.RotateFail;
try magickSave(image, &mctx); try magickSave(image, &mctx);
} }

4124
src/magick_wand.zig Normal file

File diff suppressed because it is too large Load diff