From a87af38b35762d1c2c6773dddc52186d00517c83 Mon Sep 17 00:00:00 2001 From: aliyx Date: Wed, 20 Jul 2016 10:11:54 +0100 Subject: [PATCH 1/4] Adapter imagemagick version 6.9+ --- magick/wand/lib.lua | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/magick/wand/lib.lua b/magick/wand/lib.lua index 7dab75a..1cce0da 100644 --- a/magick/wand/lib.lua +++ b/magick/wand/lib.lua @@ -116,6 +116,7 @@ get_flags = function() proc:close() return flags end +local im_new = false local get_filters get_filters = function() local fname = "magick/resample.h" @@ -128,15 +129,26 @@ get_filters = function() for p in get_flags():gmatch("-I([^%s]+)") do _accum_0[_len_0] = p _len_0 = _len_0 + 1 - end + -- for im 6.9+ + local v = string.match(p, "[0-9].") + if not v and tonumber(v) then + im_new = true + end return _accum_0 end)()) } + if im_new then + fname = "MagickCore/resample.h" + end for _index_0 = 1, #prefixes do local p = prefixes[_index_0] local full = tostring(p) .. "/" .. tostring(fname) + local s_full = tostring(p) .. "/" .. tostring(s_fname) do local f = io.open(full) + if not f then + f = io.open(s_full) + end if f then local content do @@ -145,6 +157,9 @@ get_filters = function() content = _with_0 end local filter_types = content:match("(typedef enum.-FilterTypes;)") + if im_new then + filter_types = content:match("(typedef enum.-FilterType;)") + end if filter_types then ffi.cdef(filter_types) return true @@ -160,10 +175,17 @@ get_filter = function(name) end local can_resize if get_filters() then - ffi.cdef([[ MagickBooleanType MagickResizeImage(MagickWand*, - const size_t, const size_t, - const FilterTypes, const double); - ]]) + if im_new then + ffi.cdef([[ MagickBooleanType MagickResizeImage(MagickWand*, + const size_t, const size_t, + const FilterType, const double); + ]]) + else + ffi.cdef([[ MagickBooleanType MagickResizeImage(MagickWand*, + const size_t, const size_t, + const FilterTypes, const double); + ]]) + end can_resize = true end local try_to_load From 6756279210adb9581a5f21e5bb34965aeee6ee3d Mon Sep 17 00:00:00 2001 From: aliyx Date: Wed, 20 Jul 2016 10:52:05 +0100 Subject: [PATCH 2/4] Adapter imagemagick version 6.9+ --- magick/wand/lib.lua | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/magick/wand/lib.lua b/magick/wand/lib.lua index 1cce0da..b0a6853 100644 --- a/magick/wand/lib.lua +++ b/magick/wand/lib.lua @@ -116,10 +116,9 @@ get_flags = function() proc:close() return flags end -local im_new = false +local im_7 local get_filters get_filters = function() - local fname = "magick/resample.h" local prefixes = { "/usr/include/ImageMagick", "/usr/local/include/ImageMagick", @@ -129,26 +128,25 @@ get_filters = function() for p in get_flags():gmatch("-I([^%s]+)") do _accum_0[_len_0] = p _len_0 = _len_0 + 1 - -- for im 6.9+ - local v = string.match(p, "[0-9].") - if not v and tonumber(v) then - im_new = true + -- adapter im 6.9+ source install + local v = string.match(p, "[0-9]+") + if v and tonumber(v) then + im_7 = true end return _accum_0 end)()) } - if im_new then + local fname + if not im_7 then + fname = "magick/resample.h" + else fname = "MagickCore/resample.h" end for _index_0 = 1, #prefixes do local p = prefixes[_index_0] local full = tostring(p) .. "/" .. tostring(fname) - local s_full = tostring(p) .. "/" .. tostring(s_fname) do local f = io.open(full) - if not f then - f = io.open(s_full) - end if f then local content do @@ -156,8 +154,11 @@ get_filters = function() f:close() content = _with_0 end - local filter_types = content:match("(typedef enum.-FilterTypes;)") - if im_new then + -- adapter im 6.9+ + local filter_types + if not im_7 then + filter_types = content:match("(typedef enum.-FilterTypes;)") + else filter_types = content:match("(typedef enum.-FilterType;)") end if filter_types then @@ -175,15 +176,16 @@ get_filter = function(name) end local can_resize if get_filters() then - if im_new then + -- adapter im 6.9+ + if not im_7 then ffi.cdef([[ MagickBooleanType MagickResizeImage(MagickWand*, const size_t, const size_t, - const FilterType, const double); + const FilterTypes, const double); ]]) else ffi.cdef([[ MagickBooleanType MagickResizeImage(MagickWand*, const size_t, const size_t, - const FilterTypes, const double); + const FilterType, const double); ]]) end can_resize = true From 2f737ac742b4b70b7fec9d315f50ef6148dab954 Mon Sep 17 00:00:00 2001 From: aliyx Date: Thu, 21 Jul 2016 05:58:16 +0100 Subject: [PATCH 3/4] update lib.moon --- magick/wand/lib.lua | 36 ++++++++++++++++++------------------ magick/wand/lib.moon | 34 ++++++++++++++++++++++++++-------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/magick/wand/lib.lua b/magick/wand/lib.lua index b0a6853..ba0125a 100644 --- a/magick/wand/lib.lua +++ b/magick/wand/lib.lua @@ -128,22 +128,22 @@ get_filters = function() for p in get_flags():gmatch("-I([^%s]+)") do _accum_0[_len_0] = p _len_0 = _len_0 + 1 - -- adapter im 6.9+ source install - local v = string.match(p, "[0-9]+") - if v and tonumber(v) then - im_7 = true - end return _accum_0 end)()) } - local fname - if not im_7 then - fname = "magick/resample.h" - else - fname = "MagickCore/resample.h" - end for _index_0 = 1, #prefixes do local p = prefixes[_index_0] + -- adapter im 6.9+ source install + local fname = "magick/resample.h" + do + local v = string.match(p, "%d+%.?%d*") + if v then + if tonumber(v) >= 6.9 then + fname = "MagickCore/resample.h" + im_7 = true + end + end + end local full = tostring(p) .. "/" .. tostring(fname) do local f = io.open(full) @@ -154,9 +154,9 @@ get_filters = function() f:close() content = _with_0 end - -- adapter im 6.9+ + -- adapter im 6.9+ source install local filter_types - if not im_7 then + if not (im_7) then filter_types = content:match("(typedef enum.-FilterTypes;)") else filter_types = content:match("(typedef enum.-FilterType;)") @@ -176,14 +176,14 @@ get_filter = function(name) end local can_resize if get_filters() then - -- adapter im 6.9+ - if not im_7 then - ffi.cdef([[ MagickBooleanType MagickResizeImage(MagickWand*, + -- adapter im 6.9+ source install + if not (im_7) then + ffi.cdef([[ MagickBooleanType MagickResizeImage(MagickWand*, const size_t, const size_t, const FilterTypes, const double); ]]) - else - ffi.cdef([[ MagickBooleanType MagickResizeImage(MagickWand*, + else + ffi.cdef([[ MagickBooleanType MagickResizeImage(MagickWand*, const size_t, const size_t, const FilterType, const double); ]]) diff --git a/magick/wand/lib.moon b/magick/wand/lib.moon index 62ba6d0..027cf9c 100644 --- a/magick/wand/lib.moon +++ b/magick/wand/lib.moon @@ -111,7 +111,6 @@ ffi.cdef [[ MagickBooleanType MagickAutoOrientImage(MagickWand *wand); ]] - get_flags = -> proc = io.popen "pkg-config --cflags --libs MagickWand", "r" flags = proc\read "*a" @@ -119,8 +118,8 @@ get_flags = -> proc\close! flags +local im_7 get_filters = -> - fname = "magick/resample.h" prefixes = { "/usr/include/ImageMagick" "/usr/local/include/ImageMagick" @@ -128,10 +127,21 @@ get_filters = -> } for p in *prefixes + -- adapter im 6.9+ source install + fname = "magick/resample.h" + if v = string.match(p, "%d+%.?%d*") + if tonumber(v) >= 6.9 + fname = "MagickCore/resample.h" + im_7 = true full = "#{p}/#{fname}" if f = io.open full content = with f\read "*a" do f\close! - filter_types = content\match "(typedef enum.-FilterTypes;)" + -- adapter im 6.9+ source install + local filter_types + unless im_7 + filter_types = content\match "(typedef enum.-FilterTypes;)" + else + filter_types = content\match "(typedef enum.-FilterType;)" if filter_types ffi.cdef filter_types return true @@ -142,11 +152,19 @@ get_filter = (name) -> lib[name .. "Filter"] can_resize = if get_filters! - ffi.cdef [[ - MagickBooleanType MagickResizeImage(MagickWand*, - const size_t, const size_t, - const FilterTypes, const double); - ]] + -- adapter im 6.9+ source install + unless im_7 + ffi.cdef [[ + MagickBooleanType MagickResizeImage(MagickWand*, + const size_t, const size_t, + const FilterTypes, const double); + ]] + else + ffi.cdef [[ + MagickBooleanType MagickResizeImage(MagickWand*, + const size_t, const size_t, + const FilterType, const double); + ]] true try_to_load = (...) -> From 94a5da2f0049c925b7b109654450970e8e475f7d Mon Sep 17 00:00:00 2001 From: aliyx Date: Thu, 21 Jul 2016 06:12:31 +0100 Subject: [PATCH 4/4] missing end in for ... --- magick/wand/lib.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/magick/wand/lib.lua b/magick/wand/lib.lua index ba0125a..cce5b9e 100644 --- a/magick/wand/lib.lua +++ b/magick/wand/lib.lua @@ -128,6 +128,7 @@ get_filters = function() for p in get_flags():gmatch("-I([^%s]+)") do _accum_0[_len_0] = p _len_0 = _len_0 + 1 + end return _accum_0 end)()) }