Skip to content

Initialize pointers at runtime #93

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jun 6, 2017
Merged
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
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,14 @@ some of your workarounds might interfere with the new approach. You can reset yo

```julia
using Homebrew
run(`brew remove imagemagick@6`)
run(`brew prune`)
Homebrew.rm("imagemagick@6")
Homebrew.brew(`prune`)
Pkg.build("ImageMagick")
```

You may also find [debugging
Homebrew](https://github.com/JuliaLang/Homebrew.jl/wiki/Debugging-Homebrew.jl)
useful.
useful.

Finally, an alternative to ImageMagick on OS X is
[QuartzImageIO](https://github.com/JuliaIO/QuartzImageIO.jl).
Expand Down
100 changes: 31 additions & 69 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,116 +15,78 @@ libwand = library_dependency("libwand", aliases = aliases)

mpath = get(ENV, "MAGICK_HOME", "") # If MAGICK_HOME is defined, add to library search path
if !isempty(mpath)
init_fun =
"""
function init_deps()
ccall((:MagickWandGenesis, libwand), Void, ())
end
"""

provides(Binaries, mpath, libwand, preload = init_fun, onload = "init_deps()")
provides(Binaries, joinpath(mpath, "lib"), libwand, preload = init_fun, onload = "init_deps()")
provides(Binaries, mpath, libwand)
provides(Binaries, joinpath(mpath, "lib"), libwand)
end


if is_linux()
init_fun =
"""
function init_deps()
ccall((:MagickWandGenesis, libwand), Void, ())
end
"""

provides(AptGet, "libmagickwand4", libwand, preload = init_fun, onload = "init_deps()")
provides(AptGet, "libmagickwand5", libwand, preload = init_fun, onload = "init_deps()")
provides(AptGet, "libmagickwand-6.q16-2", libwand, preload = init_fun, onload = "init_deps()")
provides(Pacman, "imagemagick", libwand, preload = init_fun, onload = "init_deps()")
provides(Yum, "ImageMagick", libwand, preload = init_fun, onload = "init_deps()")
provides(AptGet, "libmagickwand4", libwand)
provides(AptGet, "libmagickwand5", libwand)
provides(AptGet, "libmagickwand-6.q16-2", libwand)
provides(Pacman, "imagemagick", libwand)
provides(Yum, "ImageMagick", libwand)
end


if is_windows()
push!(BinDeps.defaults, BuildProcess) # TODO: remove me when upstream is fixed

const OS_ARCH = Sys.WORD_SIZE == 64 ? "x64" : "x86"
OS_ARCH = Sys.WORD_SIZE == 64 ? "x64" : "x86"

# TODO: checksums: we have gpg
# Extract the appropriate filename to download
magick_base = "http://www.imagemagick.org/download/binaries"
binariesfn = download(magick_base)
str = readstring(binariesfn)
pattern = "ImageMagick-6.9.*?-Q16-$(OS_ARCH)-dll.exe"
m = match(Regex(pattern), str)
magick_exe = convert(String, m.match)

magick_tmpdir = BinDeps.downloadsdir(libwand)
magick_url = "$(magick_base)/$(magick_exe)"
magick_libdir = joinpath(BinDeps.libdir(libwand), OS_ARCH)
innounp_url = "https://bintray.com/artifact/download/julialang/generic/innounp.exe"
init_fun =
magick_exe = String(match(Regex(pattern), str).match)

magick_tmpdir = BinDeps.downloadsdir(libwand)
magick_url = "$(magick_base)/$(magick_exe)"
magick_installdir = joinpath(BinDeps.libdir(libwand), OS_ARCH)
magick_libdir = joinpath(magick_installdir, "{app}")
innounp_url = "https://bintray.com/artifact/download/julialang/generic/innounp.exe"
preloads =
"""
function init_deps()
ENV["MAGICK_CONFIGURE_PATH"] = \"$(escape_string(magick_libdir))\"
ENV["MAGICK_CODER_MODULE_PATH"] = \"$(escape_string(magick_libdir))\"
function initenv()
ENV["MAGICK_CONFIGURE_PATH"] = "$(escape_string(magick_libdir))"
ENV["MAGICK_CODER_MODULE_PATH"] = "$(escape_string(joinpath(magick_libdir, "modules", "coders")))"
ENV["MAGICK_FILTER_MODULE_PATH"] = "$(escape_string(joinpath(magick_libdir, "modules", "filters")))"
ENV["PATH"] = "$(escape_string(magick_libdir * ";"))" * ENV["PATH"]
end
"""

provides(BuildProcess,
(@build_steps begin
CreateDirectory(magick_tmpdir)
CreateDirectory(magick_libdir)
FileDownloader(magick_url, joinpath(magick_tmpdir, magick_exe))
FileDownloader(innounp_url, joinpath(magick_tmpdir, "innounp.exe"))
@build_steps begin
ChangeDirectory(magick_tmpdir)
info("Installing ImageMagick library")
`innounp.exe -q -y -b -e -x -d$(magick_libdir) $(magick_exe)`
`innounp.exe -q -y -b -x -d$(magick_installdir) $(magick_exe)`
end
end),
libwand, os = :Windows, unpacked_dir = magick_libdir, preload = init_fun,
onload = "init_deps()")
libwand, os = :Windows, unpacked_dir = magick_libdir, preload = preloads)
end


if is_apple()
using Homebrew
imagemagick_prefix = Homebrew.prefix("staticfloat/juliadeps/imagemagick@6")
init_fun =
homebrew_prefix = Homebrew.prefix()
preloads =
"""
function init_deps()
ENV["MAGICK_CONFIGURE_PATH"] = joinpath("$(imagemagick_prefix)",
"lib", "ImageMagick", "config-Q16")
ENV["MAGICK_CODER_MODULE_PATH"] = joinpath("$(imagemagick_prefix)",
"lib", "ImageMagick", "modules-Q16", "coders")
ENV["PATH"] = joinpath("$(imagemagick_prefix)", "bin") * ":" * ENV["PATH"]

ccall((:MagickWandGenesis,libwand), Void, ())
function initenv()
ENV["MAGICK_CONFIGURE_PATH"] = "$(escape_string(joinpath(homebrew_prefix, "opt", "imagemagick@6", "lib", "ImageMagick", "config-Q16")))"
ENV["MAGICK_CODER_MODULE_PATH"] = "$(escape_string(joinpath(homebrew_prefix, "opt", "imagemagick@6", "lib", "ImageMagick", "modules-Q16", "coders")))"
ENV["MAGICK_FILTER_MODULE_PATH"] = "$(escape_string(joinpath(homebrew_prefix, "opt", "imagemagick@6", "lib", "ImageMagick", "modules-Q16", "filters")))"
ENV["PATH"] = "$(escape_string(joinpath(homebrew_prefix, "opt", "imagemagick@6", "bin") * ":"))" * ENV["PATH"]
end
"""
provides(Homebrew.HB, "staticfloat/juliadeps/imagemagick@6", libwand, os = :Darwin,
preload = init_fun, onload = "init_deps()")
provides(Homebrew.HB, "homebrew/core/imagemagick@6", libwand, os = :Darwin, preload = preloads)
end


@BinDeps.install Dict([(:libwand, :libwand)])

# Hack-fix for issue #12
# Check to see whether init_deps is present, and if not add it
if isempty(search(readstring(joinpath(dirname(@__FILE__),"deps.jl")), "init_deps"))
open("deps.jl", "a") do io
write(io, init_fun)
end
end

module CheckVersion
include("deps.jl")
p = ccall((:MagickQueryConfigureOption, libwand), Ptr{UInt8}, (Ptr{UInt8}, ),
"LIB_VERSION_NUMBER")
vstr = string("v\"", join(split(unsafe_string(p), ',')[1:3], '.'), "\"")
open(joinpath(dirname(@__FILE__), "versioninfo.jl"), "w") do file
write(file, "const libversion = $vstr\n")
end
end


is_windows() && pop!(BinDeps.defaults)
4 changes: 2 additions & 2 deletions src/ImageMagick.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ include("libmagickwand.jl")

# Image / Video formats

image_formats = [
const image_formats = [
format"BMP",
format"AVI",
format"CRW",
Expand Down Expand Up @@ -152,7 +152,7 @@ function image2wand(img, mapi=identity, quality=nothing, permute_horizontal=true
T = eltype(imgw)
channelorder = T<:Real ? "Gray" : ColorTypes.colorant_string(T)
if T <: Union{RGB,RGBA,ARGB,BGRA,ABGR}
cs = libversion > v"6.7.5" ? "sRGB" : "RGB"
cs = getlibversion() > v"6.7.5" ? "sRGB" : "RGB"
else
cs = channelorder
end
Expand Down
Loading