move to graphicsmagick
This commit is contained in:
parent
8784f3baf9
commit
6775773674
4 changed files with 4143 additions and 18 deletions
12
build.zig
12
build.zig
|
@ -10,17 +10,11 @@ pub fn build(b: *Builder) void {
|
|||
exe.linkSystemLibrary("sndfile");
|
||||
exe.linkSystemLibrary("c");
|
||||
|
||||
// magick libraries
|
||||
exe.linkSystemLibrary("MagickWand-7.Q16HDRI");
|
||||
exe.linkSystemLibrary("MagickCore-7.Q16HDRI");
|
||||
|
||||
//exe.addArgs([_]u8{
|
||||
// "-DMAGICKCORE_HDRI_ENABLE=1",
|
||||
// "-DMAGICKCORE_QUANTUM_DEPTH=16",
|
||||
//});
|
||||
exe.linkSystemLibrary("GraphicsMagickWand");
|
||||
exe.linkSystemLibrary("GraphicsMagick");
|
||||
|
||||
exe.addIncludeDir("/usr/include/lilv-0");
|
||||
exe.addIncludeDir("/usr/include/ImageMagick-7");
|
||||
exe.addIncludeDir("/usr/include/GraphicsMagick");
|
||||
|
||||
const run_cmd = exe.run();
|
||||
run_cmd.step.dependOn(b.getInstallStep());
|
||||
|
|
|
@ -340,7 +340,7 @@ pub const Image = struct {
|
|||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
|
|
@ -4,15 +4,13 @@ const images = @import("image.zig");
|
|||
|
||||
const Image = images.Image;
|
||||
|
||||
const mc = @cImport({
|
||||
@cInclude("MagickWand/MagickWand.h");
|
||||
});
|
||||
const mc = @import("magick_wand.zig");
|
||||
|
||||
pub const MagickContext = struct {
|
||||
wand: *mc.MagickWand,
|
||||
|
||||
pub fn init() !MagickContext {
|
||||
mc.MagickWandGenesis();
|
||||
mc.InitializeMagick(null);
|
||||
|
||||
var wand = mc.NewMagickWand();
|
||||
if (wand == null) return error.WandCreateFail;
|
||||
|
@ -24,7 +22,7 @@ pub const MagickContext = struct {
|
|||
|
||||
pub fn deinit(self: *MagickContext) void {
|
||||
_ = mc.DestroyMagickWand(self.wand);
|
||||
mc.MagickWandTerminus();
|
||||
mc.DestroyMagick();
|
||||
}
|
||||
|
||||
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);
|
||||
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 mctx;
|
||||
|
@ -58,7 +58,7 @@ fn magickSave(image: *Image, mctx: *MagickContext) !void {
|
|||
c_tmpnam,
|
||||
);
|
||||
|
||||
if (mc.MagickWriteImages(mctx.wand, c_tmpnam.ptr, .MagickTrue) == .MagickFalse)
|
||||
if (mc.MagickWriteImage(mctx.wand, c_tmpnam.ptr) != 1)
|
||||
return error.MagickWriteFail;
|
||||
}
|
||||
|
||||
|
@ -66,7 +66,14 @@ pub fn runRotate(image: *Image) !void {
|
|||
var mctx = try magickLoad(image);
|
||||
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);
|
||||
}
|
||||
|
|
4124
src/magick_wand.zig
Normal file
4124
src/magick_wand.zig
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue