Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions magick/wand/lib.lua
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ get_flags = function()
proc:close()
return flags
end
local im_7
local get_filters
get_filters = function()
local fname = "magick/resample.h"
local prefixes = {
"/usr/include/ImageMagick",
"/usr/local/include/ImageMagick",
Expand All @@ -134,6 +134,17 @@ get_filters = function()
}
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)
Expand All @@ -144,7 +155,13 @@ get_filters = function()
f:close()
content = _with_0
end
local filter_types = content:match("(typedef enum.-FilterTypes;)")
-- adapter im 6.9+ source install
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
ffi.cdef(filter_types)
return true
Expand All @@ -160,10 +177,18 @@ 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);
]])
-- 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*,
const size_t, const size_t,
const FilterType, const double);
]])
end
can_resize = true
end
local try_to_load
Expand Down
34 changes: 26 additions & 8 deletions magick/wand/lib.moon
Original file line number Diff line number Diff line change
Expand Up @@ -111,27 +111,37 @@ ffi.cdef [[
MagickBooleanType MagickAutoOrientImage(MagickWand *wand);
]]


get_flags = ->
proc = io.popen "pkg-config --cflags --libs MagickWand", "r"
flags = proc\read "*a"
get_flags = -> flags
proc\close!
flags

local im_7
get_filters = ->
fname = "magick/resample.h"
prefixes = {
"/usr/include/ImageMagick"
"/usr/local/include/ImageMagick"
unpack [p for p in get_flags!\gmatch "-I([^%s]+)"]
}

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
Expand All @@ -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 = (...) ->
Expand Down