From f2aebaba59ce7ee4addbadcc889684e83845c76a Mon Sep 17 00:00:00 2001 From: "kwanhur.huang" Date: Wed, 20 Sep 2017 10:10:17 +0800 Subject: [PATCH 1/3] add get and set image profile to image magick --- magick/wand/image.lua | 8 ++++++++ magick/wand/lib.lua | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/magick/wand/image.lua b/magick/wand/image.lua index 21a1d19..4c452e5 100644 --- a/magick/wand/image.lua +++ b/magick/wand/image.lua @@ -238,6 +238,14 @@ do itype = assert(interlace:to_int(itype), "invalid interlace type") return lib.MagickSetImageInterlaceScheme(self.wand, itype) end, + get_profile = function(self, profile) + local len = ffi.new("size_t[1]", 0) + local blob = ffi.gc(lib.MagickGetImageProfile(self.wand, profile, len), lib.MagickRelinquishMemory) + return ffi.string(blob, len[0]) + end, + set_profile = function(self, profile, value) + return handle_result(self, lib.MagickSetImageProfile(self.wand, profile, value, #value)) + end, auto_orient = function(self) return handle_result(self, lib.MagickAutoOrientImage(self.wand)) end, diff --git a/magick/wand/lib.lua b/magick/wand/lib.lua index d5ab763..7a66cf9 100644 --- a/magick/wand/lib.lua +++ b/magick/wand/lib.lua @@ -114,6 +114,12 @@ ffi.cdef([[ typedef void MagickWand; MagickBooleanType MagickSetImageDepth(MagickWand *,const unsigned long); unsigned long MagickGetImageDepth(MagickWand *); + unsigned char *MagickGetImageProfile(MagickWand *wand,const char *name, + size_t *length); + + MagickBooleanType MagickSetImageProfile(MagickWand *wand,const char *name, + const void *profile,const size_t length); + ]]) local get_flags get_flags = function() From df467015f36b039bcb6a7f3aa1b044042cabbcf9 Mon Sep 17 00:00:00 2001 From: "kwanhur.huang" Date: Thu, 28 Sep 2017 20:09:42 +0800 Subject: [PATCH 2/3] update resize with support for imagemagick FilterType --- magick/wand/data.lua | 37 ++++++++++++++++++++++++++++++++++++- magick/wand/image.lua | 5 +++-- magick/wand/lib.lua | 39 +++------------------------------------ 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/magick/wand/data.lua b/magick/wand/data.lua index dec9a4c..82fe0a1 100644 --- a/magick/wand/data.lua +++ b/magick/wand/data.lua @@ -105,9 +105,44 @@ local interlace = enum({ "JPEGInterlace", "PNGInterlace" }) +local filtertype = enum({ + [0] = "UndefinedFilter", + "PointFilter", + "TriangleFilter", + "HermiteFilter", + "HannFilter", + "HammingFilter", + "BlackmanFilter", + "GaussianFilter", + "QuadraticFilter", + "CubicFilter", + "CatromFilter", + "MitchellFilter", + "JincFilter", + "SincFilter", + "SincFastFilter", + "KaiserFilter", + "WelchFilter", + "ParzenFilter", + "BohmanFilter", + "BartlettFilter", + "LagrangeFilter", + "LanczosFilter", + "LanczosSharpFilter", + "Lanczos2Filter", + "Lanczos2SharpFilter", + "RobidouxFilter", + "RobidouxSharpFilter", + "CosineFilter", + "SplineFilter", + "LanczosRadiusFilter", + "CubicSplineFilter", + "SentinelFilter" +}) return { composite_operators = composite_operators, gravity = gravity, orientation = orientation, - interlace = interlace + interlace = interlace, + filtertype = filtertype } diff --git a/magick/wand/image.lua b/magick/wand/image.lua index 4c452e5..35d3257 100644 --- a/magick/wand/image.lua +++ b/magick/wand/image.lua @@ -4,10 +4,11 @@ do local _obj_0 = require("magick.wand.lib") lib, can_resize, get_filter = _obj_0.lib, _obj_0.can_resize, _obj_0.get_filter end -local composite_operators, gravity, orientation, interlace +local composite_operators, gravity, orientation, interlace, filtertype do local _obj_0 = require("magick.wand.data") composite_operators, gravity, orientation, interlace = _obj_0.composite_operators, _obj_0.gravity, _obj_0.orientation, _obj_0.interlace + filtertype = _obj_0.filtertype end local get_exception get_exception = function(wand) @@ -101,7 +102,7 @@ do error("Failed to load filter list, can't resize") end w, h = self:_keep_aspect(w, h) - return handle_result(self, lib.MagickResizeImage(self.wand, w, h, get_filter(f), blur)) + return handle_result(self, lib.MagickResizeImage(self.wand, w, h, filtertype:to_int(f .. 'Filter'), blur)) end, adaptive_resize = function(self, w, h) w, h = self:_keep_aspect(w, h) diff --git a/magick/wand/lib.lua b/magick/wand/lib.lua index 7a66cf9..015af8f 100644 --- a/magick/wand/lib.lua +++ b/magick/wand/lib.lua @@ -10,6 +10,7 @@ ffi.cdef([[ typedef void MagickWand; typedef int GravityType; typedef int OrientationType; typedef int InterlaceType; + typedef int FilterType; void MagickWandGenesis(); MagickWand* NewMagickWand(); @@ -133,41 +134,7 @@ get_flags = function() end local get_filters get_filters = function() - local fname = "magick/resample.h" - local prefixes = { - "/usr/include/ImageMagick", - "/usr/local/include/ImageMagick", - unpack((function() - local _accum_0 = { } - local _len_0 = 1 - for p in get_flags():gmatch("-I([^%s]+)") do - _accum_0[_len_0] = p - _len_0 = _len_0 + 1 - end - return _accum_0 - end)()) - } - for _index_0 = 1, #prefixes do - local p = prefixes[_index_0] - local full = tostring(p) .. "/" .. tostring(fname) - do - local f = io.open(full) - if f then - local content - do - local _with_0 = f:read("*a") - f:close() - content = _with_0 - end - local filter_types = content:match("(typedef enum.-FilterTypes;)") - if filter_types then - ffi.cdef(filter_types) - return true - end - end - end - end - return false + return true end local get_filter get_filter = function(name) @@ -177,7 +144,7 @@ local can_resize if get_filters() then ffi.cdef([[ MagickBooleanType MagickResizeImage(MagickWand*, const size_t, const size_t, - const FilterTypes, const double); + const FilterType, const double); ]]) can_resize = true end From caffec7d63804515022f04564ad82430ac53fe70 Mon Sep 17 00:00:00 2001 From: "kwanhur.huang" Date: Fri, 3 Nov 2017 16:14:20 +0800 Subject: [PATCH 3/3] updated: fix filterType with BoxFilter --- magick/wand/data.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/magick/wand/data.lua b/magick/wand/data.lua index 82fe0a1..fc2a0fc 100644 --- a/magick/wand/data.lua +++ b/magick/wand/data.lua @@ -108,6 +108,7 @@ local interlace = enum({ local filtertype = enum({ [0] = "UndefinedFilter", "PointFilter", + "BoxFilter", "TriangleFilter", "HermiteFilter", "HannFilter", @@ -144,5 +145,5 @@ return { gravity = gravity, orientation = orientation, interlace = interlace, - filtertype = filtertype + filtertype = filtertype }